web: add `post` helper to Api module
-module Api exposing (Method(..), get, ignoreResponse, paginatedGet, request)
+module Api exposing (Method(..), get, ignoreResponse, paginatedGet, post, request)
import Api.Endpoints exposing (Endpoint, toUrl)
+import Concourse
import Concourse.Pagination exposing (Paginated)
import Http
import Json.Decode exposing (Decoder)
@@ -10,6 +11,7 @@ import Task exposing (Task)
type Method
= Get
+ | Post
methodToString : Method -> String
@@ -18,6 +20,9 @@ methodToString m =
Get ->
"GET"
+ Post ->
+ "POST"
+
request :
{ endpoint : Endpoint
@@ -62,6 +67,17 @@ paginatedGet endpoint decoder =
}
+post : Endpoint -> Concourse.CSRFToken -> Http.Body -> Task Http.Error ()
+post endpoint csrfToken body =
+ request
+ { method = Post
+ , headers = [ Http.header Concourse.csrfTokenHeaderName csrfToken ]
+ , endpoint = endpoint
+ , body = body
+ , expect = ignoreResponse
+ }
+
+
ignoreResponse : Http.Expect ()
ignoreResponse =
Http.expectStringResponse <| always <| Ok ()
