aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Utils/Http.elm
diff options
context:
space:
mode:
authorJoris2016-06-27 14:36:03 +0200
committerJoris2016-06-27 14:36:03 +0200
commitf605541cbaaa3c339eef8f345547bcd653d3f721 (patch)
tree1e800df7736e482290ca138726595e067e4a5cf9 /src/client/elm/Utils/Http.elm
parent885dfd7708e338a3220c85b7f22a3ac267aad3f7 (diff)
downloadbudget-f605541cbaaa3c339eef8f345547bcd653d3f721.tar.gz
budget-f605541cbaaa3c339eef8f345547bcd653d3f721.tar.bz2
budget-f605541cbaaa3c339eef8f345547bcd653d3f721.zip
Add the edit functionnality on payments
Diffstat (limited to 'src/client/elm/Utils/Http.elm')
-rw-r--r--src/client/elm/Utils/Http.elm30
1 files changed, 16 insertions, 14 deletions
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)
_ ->