Skip to content

Haskell HTTP client library for use with io-streams

License

Notifications You must be signed in to change notification settings

tiago-loureiro/http-streams

 
 

Repository files navigation

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
    
    q <- buildRequest $ 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

Recent API changes:

  • 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

AfC

About

Haskell HTTP client library for use with io-streams

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 100.0%