Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

In addition to Network.HTTP.Conduit there Network.Http.Client which exposes an io-streams interface.

Servant is easy to use (albeit hard to understand) and magical. It lets you specify the API as an uninhabited type, and generates request and response behaviors based on it. You'll never have to worry about serialization or deserialization, or even JSON -- it converts JSON to and from native Haskell objects automatically, based on the API. It's got an excellent tutorial, too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top