2

Trying to construct a Request with Network.HTTP.Conduit package. The instructions are:

The constructor for this data type is not exposed. Instead, you should use either the def method to retrieve a default instance, or parseUrl to construct from a URL, and then use the records below to make modifications...

I have no idea what this means. How can I "make modifications" to an immutable Request object; furthermore none of the functions "below" return a Request object!

This is as far as I got:

main = do
    let req = def :: String
    putStrLn "What now? How do I make it a POST?"

Although I am not sure why I used String above either.

Any help appreciated.

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272

1 Answers1

5

It's not at all clear from the documentation, but the "functions below" are actually record labels, so you can use record update syntax to construct the request you want. Of course "modify" here means creating a new request based on the default one, not an actual destructive update.

In other words, something like this:

let req = def { method = methodPost, ... }
hammar
  • 138,522
  • 17
  • 304
  • 385
  • 1
    You're right, it's not clear. I just added some comments which I hope clarify things a bit: https://github.com/snoyberg/http-conduit/commit/82e0e77291eafa83969abc539ea9ad63fb6a9f8a . The explanation of this setup (what I call a settings type) is available at: http://www.yesodweb.com/book/settings-types – Michael Snoyman Apr 03 '12 at 17:01
  • @MichaelSnoyman Don't you mean `def` instead of `req` in: `let req = req`? – Andriy Drozdyuk Apr 03 '12 at 17:54
  • Doh, the problem is that I meant `let req = initReq {`. The idea is that you let the `parseUrl` function handle most of the work for you, and then just tweak is afterwards. – Michael Snoyman Apr 04 '12 at 04:11