HTTP-4000.0.6: A library for client-side HTTP

Portabilitynon-portable (not tested)
MaintainerSigbjorn Finne <>



The Network.HTTP module provides a simple interface for sending and receiving content over HTTP in Haskell. Here's how to fetch a document from a URL and return it as a String:

    simpleHTTP (getRequest "") >>= fmap (take 100) . getResponseBody
        -- fetch document and return it (as a 'String'.)

Other functions let you control the submission and transfer of HTTP Requests and Responses more carefully, letting you integrate the use of Network.HTTP functionality into your application.

The module also exports the main types of the package, Request and Response, along with Header and functions for working with these.

The actual functionality is implemented by modules in the Network.HTTP.* namespace, letting you either use the default implementation here by importing Network.HTTP or, for more specific uses, selectively import the modules in Network.HTTP.*. To wit, more than one kind of representation of the bulk data that flows across a HTTP connection is supported. (see Network.HTTP.HandleStream.)

NOTE: The Request send actions will normalize the Request prior to transmission. Normalization such as having the request path be in the expected form and, possibly, introduce a default Host: header if one isn't already present. If you do not want the requests tampered with, but sent as-is, please import and use the the Network.HTTP.HandleStream or Network.HTTP.Stream modules instead. They export the same functions, but leaves construction and any normalization of Requests to the user.




simpleHTTP req transmits the Request req by opening a direct, non-persistent connection to the HTTP server that req is destined for, followed by transmitting it and gathering up the response as a Result. Prior to sending the request, it is normalized (via normalizeRequest). If you have to mediate the request via an HTTP proxy, you will have to normalize the request yourself. Or switch to using Network.Browser instead.


 simpleHTTP (getRequest "")
 simpleHTTP (getRequest "")


Identical to simpleHTTP, but acting on an already opened stream.


sendHTTP hStream httpRequest transmits httpRequest (after normalization) over hStream, but does not alter the status of the connection, nor request it to be closed upon receiving the response.



receiveHTTP :: HStream ty => HandleStream ty -> IO (Result (Request ty))Source

receiveHTTP hStream reads a Request from the HandleStream hStream



getRequest :: String -> Request_StringSource

getRequest urlString is convenience constructor for basic GET Requests. If urlString isn't a syntactically valid URL, the function raises an error.

postRequest :: String -> Request_StringSource

postRequest urlString is convenience constructor for POST Requests. If urlString isn't a syntactically valid URL, the function raises an error.

getResponseBody :: Result (Response ty) -> IO tySource

getResponseBody response takes the response of a HTTP requesting action and tries to extricate the body of the Response response. If the request action returned an error, an IO exception is raised.