What is the recommended library for web client programming which involves HTTP requests.
I know there is a package called HTTP but it doesn't seem to support HTTPS. Is there any better library for it ?
I expect a library with functionality something like this for Haskell.
Network.HTTP.Conduit
has a clean API (it uses Network.HTTP.Types
) and is quite simple to use if you know a bit about conduits. Example:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Conduit
import Network.HTTP.Conduit
import qualified Data.Aeson as J
main =
do manager <- newManager def
initReq <- parseUrl "https://api.github.com/user"
let req = applyBasicAuth "niklasb" "password" initReq
resp <- runResourceT $ httpLbs req manager
print (responseStatus resp)
print (lookup "content-type" (responseHeaders resp))
-- you will probably want a proper FromJSON instance here,
-- rather than decoding to Data.Aeson.Object
print (J.decode (responseBody resp) :: Maybe J.Object)
Also make sure to consult the tutorial.
A library named wreq has been released by Bryan O'Sullivan which is great and easy to use for HTTP communication.
A related tutorial for that by the same author is here.
There is also another library named req which provides a nice API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With