Send a GET request to the given URL. You also specify how to decode the response.
import Json.Decode (list, string)
hats : Task (Error (List String)) (List String)
hats =
get (decoder (list string) (succeed ())) "http://example.com/hat-categories.json"Send a POST request to the given URL. You also specify how to decode the response.
import Json.Decode (list, string)
import Http
hats : Task (Error (List String)) (List String)
hats =
post (decoder (list string) (succeed ())) "http://example.com/hat-categories.json" Http.emptyUtility for working with Rails. Wraps Http.send, passing an Authenticity Token along with the type of request. Suitable for use with fromJson:
import Dict
import Json.Decode (list, string)
import Json.Encode as Encode
import Http
hats : HatStyle -> Task (Error (List String)) (List String)
hats style =
let
payload =
Encode.object
[ ( "style", encodeHatStyle style ) ]
body =
Http.string (Encode.encode 0 payload)
success =
list string
failure =
Dict.fromList [ ("style", HatStyle) ]
|> Rails.Decode.errors
in
send "POST" url body
|> fromJson (decoder success failure)Think Http.fromJson, but with additional effort to parse a non-20x response as JSON.
* If the status code is in the 200 range, try to parse with the given decoder.success.
* If parsing fails, return an Http.UnexpectedPayload wrapped in HttpError
* If the status code is outside the 200 range, try to parse with the given decoder.success.
* If parsing fails, return an Http.BadResponse wrapped in HttpError
Returns a decoder suitable for passing to fromJson, which uses the same decoder for both success and failure responses.
Returns a decoder suitable for passing to fromJson.
If there was a <meta name="csrf-token"> tag in the page's <head> when
elm-rails loaded, returns the value its content attribute had at that time.
Rails expects this value in the `X-CSRF-Token` header for non-`GET` requests as
a [CSRF countermeasure](http://guides.rubyonrails.org/security.html#csrf-countermeasures).
The kinds of errors a Rails server may return.