Hoogle Search
Within Stackage Nightly 2026-01-08 (ghc-9.12.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
module Network.HTTP.Client.
Conduit A new, experimental API to replace Network.HTTP.Conduit. For most users, Network.HTTP.Simple is probably a better choice. For more information, see: https://haskell-lang.org/library/http-client For more information on using this module, please be sure to read the documentation in the Network.HTTP.Client module.
-
Simpler API
The API below is rather low-level. The Network.HTTP.Simple module provides a higher-level API with built-in support for things like JSON request and response bodies. For most users, this will be an easier place to start. You can read the tutorial at: https://haskell-lang.org/library/http-clientLower-level API
This module contains everything you need to initiate HTTP connections. If you want a simple interface based on URLs, you can use simpleHttp. If you want raw power, http is the underlying workhorse of this package. Some examples:-- Just download an HTML document and print it. import Network.HTTP.Conduit import qualified Data.ByteString.Lazy as L main = simpleHttp "http://www.haskell.org/" >>= L.putStr
This example uses interleaved IO to write the response body to a file in constant memory space.import Data.Conduit.Binary (sinkFile) -- Exported from the package conduit-extra import Network.HTTP.Conduit import Conduit (runConduit, (.|)) import Control.Monad.Trans.Resource (runResourceT) main :: IO () main = do request <- parseRequest "http://google.com/" manager <- newManager tlsManagerSettings runResourceT $ do response <- http request manager runConduit $ responseBody response .| sinkFile "google.html"
The following headers are automatically set by this module, and should not be added to requestHeaders:- Cookie
- Content-Length
- Transfer-Encoding
{-# LANGUAGE OverloadedStrings #-} import Network.HTTP.Conduit import Network import Data.Time.Clock import Data.Time.Calendar import qualified Control.Exception as E import Network.HTTP.Types.Status (statusCode) past :: UTCTime past = UTCTime (ModifiedJulianDay 56200) (secondsToDiffTime 0) future :: UTCTime future = UTCTime (ModifiedJulianDay 562000) (secondsToDiffTime 0) cookie :: Cookie cookie = Cookie { cookie_name = "password_hash" , cookie_value = "abf472c35f8297fbcabf2911230001234fd2" , cookie_expiry_time = future , cookie_domain = "example.com" , cookie_path = "/" , cookie_creation_time = past , cookie_last_access_time = past , cookie_persistent = False , cookie_host_only = False , cookie_secure_only = False , cookie_http_only = False } main = do request' <- parseRequest "http://example.com/secret-page" manager <- newManager tlsManagerSettings let request = request' { cookieJar = Just $ createCookieJar [cookie] } fmap Just (httpLbs request manager) `E.catch` (\ex -> case ex of HttpExceptionRequest _ (StatusCodeException res _) -> if statusCode (responseStatus res) == 403 then (putStrLn "login failed" >> return Nothing) else return Nothing _ -> E.throw ex)Cookies are implemented according to RFC 6265. Note that by default, the functions in this package will throw exceptions for non-2xx status codes. If you would like to avoid this, you should use checkStatus, e.g.:import Data.Conduit.Binary (sinkFile) import Network.HTTP.Conduit import qualified Data.Conduit as C import Network main :: IO () main = do request' <- parseRequest "http://www.yesodweb.com/does-not-exist" let request = request' { checkStatus = \_ _ _ -> Nothing } manager <- newManager tlsManagerSettings res <- httpLbs request manager print resBy default, when connecting to websites using HTTPS, functions in this package will throw an exception if the TLS certificate doesn't validate. To continue the HTTPS transaction even if the TLS cerficate validation fails, you should use mkManagerSetttings as follows:import Network.Connection (TLSSettings (..)) import Network.HTTP.Conduit main :: IO () main = do request <- parseRequest "https://github.com/" let settings = mkManagerSettings (TLSSettingsSimple True False False) Nothing manager <- newManager settings res <- httpLbs request manager print res
For more information, please be sure to read the documentation in the Network.HTTP.Client module. module Network.HTTP.Req.
Conduit The module extends functionality available in Network.HTTP.Req with Conduit helpers for streaming big request bodies. The package re-uses some pieces of code from the http-conduit package, but not to the extent that depending on that package becomes reasonable.
Page 1 of 1