Example abstraction layer on top of elm-http-extra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JsonApi where | |
import Task exposing (Task) | |
import Json.Decode exposing (Decoder) | |
import Json.Encode exposing (Value) | |
import Http.Extra as HttpExtra exposing (..) | |
import Task exposing (Task) | |
import Json.Decode exposing (Decoder) | |
import Json.Encode exposing (Value) | |
import Http.Extra as HttpExtra exposing (..) | |
apiCall : (String -> RequestBuilder) -> Decoder success -> Decoder error -> String -> Value -> Task (Error error) (Response success) | |
apiCall useMethod successDecoder errorDecoder url body = | |
url | |
|> useMethod | |
|> withHeader "content-type" "application/json" | |
|> withJsonBody body | |
|> send (jsonReader successDecoder) (jsonReader errorDecoder) | |
get : Decoder success -> Decoder error -> String -> Value -> Task (Error error) (Response success) | |
get = | |
apiCall HttpExtra.get | |
post : Decoder success -> Decoder error -> String -> Value -> Task (Error error) (Response success) | |
post = | |
apiCall HttpExtra.post | |
put : Decoder success -> Decoder error -> String -> Value -> Task (Error error) (Response success) | |
put = | |
apiCall HttpExtra.put | |
patch : Decoder success -> Decoder error -> String -> Value -> Task (Error error) (Response success) | |
patch = | |
apiCall HttpExtra.patch | |
delete : Decoder success -> Decoder error -> String -> Value -> Task (Error error) (Response success) | |
delete = | |
apiCall HttpExtra.delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment