Network.HTTP.Conduit
具有简洁的 API(它使用 Network.HTTP.Types
),如果您了解一些关于管道的知识,则非常容易使用。例如:
{-# 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)
请确保参考教程。
wreq
是最高级别的一个。它大量使用 lens 技术,提供了一致而简洁的接口。 - Sibi