elm-http
elm-http copied to clipboard
High level requests for verbs other than POST/GET
Currently, there are only two "high-level" HTTP functions, get
and post
. It seems to me that PUT
and DELETE
would also be very useful. What do you think?
Parenthetically, the Consul HTTP API supports GET
, PUT
, and DELETE
.
I'm currently using the following implementation of putString
, delString
:
{-| Mirror the getString API, but for PUT requests.
-}
httpPutString : String -> String -> Task Error String
httpPutString =
wrapHttpApi "PUT"
{-| Mirror the getString API, but for DELETE requests.
-}
httpDelString : String -> Task Error String
httpDelString =
flip (wrapHttpApi "DELETE") ""
{-| Create a high-level API for some HTTP verb other than GET/POST
-}
wrapHttpApi : String -> String -> String -> Task Error String
wrapHttpApi verb url body =
let
request =
{ verb = verb, headers = [], url = url, body = Http.string body }
in
Task.mapError promoteError (Http.send Http.defaultSettings request)
`andThen` handleResponse Task.succeed
with handleResponse
and promoteError
copied directly from this module's source.
The "PATCH" verb is also missing
Here's a (full?) list of HTTP methods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
I believe only the first three (GET
, HEAD
and POST
) are widely implemented in browsers? Not sure if that means only those three make sense to have in the base API (and then only HEAD
would be missing), or if it would make sense to have them all?
In any case, I'm not sure if it's relevant to have all those verbs implemented, or if something like the wrapHttpApi
helper you posted above would be more useful?
I do use the PUT
request to send Trello API request from browser directly. Currently, I am using the snippet provided above for my scenario. I think Elm should provide such abilities and leave the question support or not support to the endpoint service.
I use webmachine https://github.com/webmachine/webmachine for my backends, so yea having PUT and DELETE as first class things would be great