aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Utils/Http.elm
diff options
context:
space:
mode:
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)
_ ->