Giter Site home page Giter Site logo

romanb / http-streams Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aesiniath/http-streams

0.0 1.0 0.0 1.08 MB

Haskell HTTP client library for use with io-streams

Home Page: http://research.operationaldynamics.com/projects/http-streams/

License: Other

Haskell 100.00%

http-streams's Introduction

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

http-streams's People

Contributors

3noch avatar chemist avatar emmanueltouzery avatar erikd avatar gregorycollins avatar istathar avatar ixmatus avatar lukerandall avatar michaelxavier avatar snoyberg avatar tanakh avatar werehamster avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.