Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell library for HTTP communication

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.

like image 418
Sibi Avatar asked Apr 07 '13 19:04

Sibi


2 Answers

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.

like image 55
Niklas B. Avatar answered Nov 05 '22 18:11

Niklas B.


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.

like image 12
Sibi Avatar answered Nov 05 '22 18:11

Sibi