I want to fetch a url in the form of “https://domain.com?a=a&b=b”, below code can work without problem:
fetchIndexCommand : Cmd Msg
fetchIndexCommand =
Http.get “https://domain.com?a=a&b=b” indexDecoder
|> RemoteData.sendRequest
|> Cmd.map IndexReceived
I am trying to make it another way, make the parameters seperated, as below:
fetchIndexCommand : Cmd Msg
fetchIndexCommand =
indexRequest “https://domain.com” indexDecoder
|> RemoteData.sendRequest
|> Cmd.map IndexReceived
indexRequest : String -> Decoder a -> Http.Request a
indexRequest url decoder =
Http.request
{ method = “GET”
, headers = []
, url = url
, body = Http.jsonBody indexEncoder
, expect = Http.expectJson decoder
, timeout = Nothing
, withCredentials = False
}
indexEncoder : Encode.Value
indexEncoder =
Encode.object
[ ( “a”, Encode.string “a” )
, ( “b”, Encode.string “b” )
]
This will not work, it will return NetworkError of RemoteData, my browser console will show OPTIONS 405 error, as well as on the server end log: REST Method Not Supported (405): Method options not supported at…
The Http.get is also Http.request, why the behaviour is so different? Did I make any mistake?