BSD-3-Clause licensed and maintained by Andrew Cowie
This version can be pinned in stack with:http-streams-0.8.7.2@sha256:8db4a16db9894631dfa45b1cf753c7701049df477c261a0b5fe888fd9668c9a3,4869

Module documentation for 0.8.7.2

  • Network
    • Network.Http
      • Network.Http.Client
      • Network.Http.Connection
      • Network.Http.Inconvenience
      • Network.Http.ResponseParser

An HTTP client

An HTTP client library for Haskell using the Snap Framework’s io-streams library to handle the streaming IO.

A common case in writing RESTful web services is needing to make onward calls to further servers. This package is intended to make this easy to do. Though originally written for making calls from wep apps written with Snap, you can use this from any library or framework.

Enjoy!

Example

The underlying API is very simple:

main :: IO ()
main = do
    c <- openConnection "www.example.com" 80
    
    let q = buildRequest1 $ do
                http GET "/"
                setAccept "text/html"
    
    sendRequest c q emptyBody
    
    receiveResponse c (\p i -> do
    	putStr $ show p

    	x <- Streams.read i
    	S.putStr $ fromMaybe "" x)
    
    closeConnection c

There are also convenience functions for the common case of making straight-forward GET and POST requests; for instance:

    get "http://www.example.com/" (\_ i -> Streams.connect i stdout)

will {ahem} stream the response body to stdout. Perhaps more interesting (though less streams-oriented), is simply getting the response as a ByteString using one of the pre-defined handlers:

    x' <- get "https://secure.example.com/" concatHandler

See the documentation in Network.Http.Client for further examples and details of usage of the API. There’s also a blog post introducing the library with a discussion of the design and usage.

Change Log

Now included in separate file CHANGELOG.

AfC

Changes

  • v0.8.6
    Internal modules are exposed. Mostly so the test suite would only depend on the library and not the code directly, but occasionally someone needed to poke at the internals. Usual warning against doing that applies. They are not visible in the generated Haddock documentation.

  • v0.8.4
    Support GHC 8.0

  • v0.8.3
    A pure version of buildRequest is now available as buildRequest1. Support for connecting to Unix domain sockets has been added.

  • v0.7.0
    The Request, Response, Headers, and RequestBuilder types have been factored out and moved to http-common. They are still exported by http-streams.

  • v0.6.0
    Entity body lengths (both for Requests and Responses) now Int64. Library depends on io-streams 1.1.

  • v0.5.0
    Definition of Hostname and Port have been changed to ByteString and Word16, respectively.

  • v0.4.0
    Type signature of buildRequest changed, removing the Connection parameter. This allows you to construct Request objects before opening a connection to the web server if you wish.

  • v0.3.1
    Initial public release