http-streams

An HTTP client using io-streams

http://github.com/afcowie/http-streams/

Version on this page:0.8.5.3@rev:1
LTS Haskell 22.13:0.8.9.9
Stackage Nightly 2024-03-14:0.8.9.9
Latest on Hackage:0.8.9.9

See all snapshots http-streams appears in

BSD-3-Clause licensed and maintained by Andrew Cowie
This version can be pinned in stack with:http-streams-0.8.5.3@sha256:5e01b6b6ef3f4e9ebe4a4735ccaf948c13aeb0d78a3c7b8284c96848cb7e234e,5194

Module documentation for 0.8.5.3

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.4
    Support GHC 8.

  • 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