Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to fetch. Possible Reasons: CORS Network Failure URL scheme must be "http" or "https" for CORS request [closed]

I'm trying to make a request to my local API from the Swagger documentation, but it always gives this error when I make the request

enter image description here

like image 832
Iago Alexandre Avatar asked Sep 06 '25 03:09

Iago Alexandre


4 Answers

These are two different types that are being used for your key.

  • %{"key" => 1} is using a string for a key.
  • %{key: 1} is short hand for %{:key => 1} which is using an atom for a key.

You can only use map.key syntax if you have atoms for keys.

like image 104
Justin Wood Avatar answered Sep 08 '25 14:09

Justin Wood


Both ways of accessing the values are syntatic sugar for Map.get/2 function.

So the difference between the two is that atoms are not garbage collected, and they are optimized by the erlang VM for things like pattern matching.

Strings are more general purpose, so because optimizations you should always try to use atoms as keys, if you can.

Now I don't know if I understood your last question, but a good "erlang" way of getting the key you want in that function would be:

as atom:

def fun1(%{key: value}) do
    value 
end

as string:

def fun1(%{"key" => value}) do
    value 
end

In both cases it will only enter the function if it matches the pattern, and your value will be already available inside the function.

like image 44
Gabriel Rufino Avatar answered Sep 08 '25 14:09

Gabriel Rufino


First check that your address is not blocked by cors, for dev tests you can use Access-Control-Allow-Origin:*. If it doesn't work for you, check that you are not using an extension on your browser, such as those that block ads. You delete it from your browser, restart it and test again, it will work.

like image 31
Soukaina EL HAYOUNI Avatar answered Sep 08 '25 15:09

Soukaina EL HAYOUNI


In my case, I was accessing the web application via 127.0.0.1:3000, once I changed it to localhost:3000, it worked, hope that helps

like image 45
Yalchin Mammadli Avatar answered Sep 08 '25 16:09

Yalchin Mammadli