From f605541cbaaa3c339eef8f345547bcd653d3f721 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 27 Jun 2016 14:36:03 +0200 Subject: Add the edit functionnality on payments --- src/client/elm/Utils/Http.elm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/client/elm/Utils/Http.elm') diff --git a/src/client/elm/Utils/Http.elm b/src/client/elm/Utils/Http.elm index 9bcfad7..4edc233 100644 --- a/src/client/elm/Utils/Http.elm +++ b/src/client/elm/Utils/Http.elm @@ -1,26 +1,28 @@ module Utils.Http exposing - ( post - , postWithBody - , delete + ( jsonRequest + , request + , requestWithBody , decodeHttpValue , errorKey ) import Http exposing (..) import Task exposing (..) -import Json.Decode as Json exposing (Decoder) +import Json.Decode as JsonDecode exposing (Decoder) +import Json.Encode as JsonEncode -post : String -> Task Error Value -post url = postWithBody url empty +jsonRequest : String -> String -> JsonEncode.Value -> Task Error Value +jsonRequest method url json = + json + |> JsonEncode.encode 0 + |> Http.string + |> requestWithBody method url -postWithBody : String -> Body -> Task Error Value -postWithBody = request "POST" +request : String -> String -> Task Error Value +request method url = requestWithBody method url empty -delete : String -> Task Error Value -delete url = request "DELETE" url empty - -request : String -> String -> Body -> Task Error Value -request method url body = +requestWithBody : String -> String -> Body -> Task Error Value +requestWithBody method url body = { verb = method , headers = [] , url = url @@ -52,7 +54,7 @@ decodeHttpValue : Decoder a -> Value -> Task Error a decodeHttpValue decoder value = case value of Text str -> - case Json.decodeString decoder str of + case JsonDecode.decodeString decoder str of Ok v -> succeed v Err msg -> fail (UnexpectedPayload msg) _ -> -- cgit v1.2.3