Skip to content
This repository was archived by the owner on May 9, 2018. It is now read-only.
This repository was archived by the owner on May 9, 2018. It is now read-only.

High level requests for verbs other than POST/GET #32

@langston-barrett

Description

@langston-barrett

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions