Manu Chawla
Manu Chawla

Reputation: 327

how to consume http post in elm with header and body

I am new in elm and try to consume web api using http post request with header and body using 0.17.1 version but did not get any documentation.

So any one help me to implement this functionality

Upvotes: 2

Views: 1633

Answers (1)

marcosh
marcosh

Reputation: 9008

The send method of the Http package gives you the possibility to create and send a custom request. For example, a post request could be something like

postRequest : Request
postRequest =
    { verb = "POST"
    , headers =
        [ ("Origin", "http://elm-lang.org")
        , ("Access-Control-Request-Method", "POST")
        , ("Access-Control-Request-Headers", "X-Custom-Header")
        ]
    , url = "http://example.com/hats"
    , body = empty
    }

You can then create the Task that represent the request using the send function like

send defaultSettings postRequest

Upvotes: 3

Related Questions