monad-http-0.1.0.0: A class of monads which can do http requests

Copyright(C) 2015 Futurice Oy
LicenseBSD-3-Clause
MaintainerOleg Grenrus <oleg.grenrus@iki.fi>
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Http

Contents

Description

MonadHttp class with basic HTTP functionality.

Synopsis

Class

class Monad m => MonadHttp m where Source

The monad capable to do HTTP requests.

Minimal complete definition

withResponse

Methods

withResponse :: Request -> (Response (BodyReaderM m) -> m a) -> m a Source

Get a single chunk of data from the response body, or an empty bytestring if no more data is available.

Note that in order to consume the entire request body, you will need to repeatedly call this function until you receive an empty ByteString as a result.

brRead :: BodyReaderM m -> m ByteString Source

Instances

Transformer

newtype HttpT m a Source

Http monad transformer, essentially ReaderT Manager.

Constructors

HttpT 

Fields

runHttpT :: Manager -> m a
 

evalHttpT :: MonadIO m => HttpT m a -> m a Source

Lower HttpT with default Manager created with tlsManagerSettings.

Utilities

httpLbs :: MonadHttp m => Request -> m (Response ByteString) Source

A convenience wrapper around withResponse which reads in the entire response body and immediately releases resources.

brConsume :: MonadHttp m => BodyReaderM m -> m [ByteString] Source

Strictly consume all remaining chunks of data from the stream.

Re-exports

data Request :: *

All information on how to connect to a host and what should be sent in the HTTP request.

If you simply wish to download from a URL, see parseUrl.

The constructor for this data type is not exposed. Instead, you should use either the def method to retrieve a default instance, or parseUrl to construct from a URL, and then use the records below to make modifications. This approach allows http-client to add configuration options without breaking backwards compatibility.

For example, to construct a POST request, you could do something like:

initReq <- parseUrl "http://www.example.com/path"
let req = initReq
            { method = "POST"
            }

For more information, please see http://www.yesodweb.com/book/settings-types.

Since 0.1.0

data Response body :: * -> *

A simple representation of the HTTP response.

Since 0.1.0

Instances