Copyright | (C) 2015 Futurice Oy |
---|---|
License | BSD-3-Clause |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Safe Haskell | None |
Language | Haskell2010 |
Control.Monad.Http
Description
MonadHttp
class with basic HTTP functionality.
- class Monad m => MonadHttp m where
- type BodyReaderM m = m ByteString
- newtype HttpT m a = HttpT {}
- evalHttpT :: MonadIO m => HttpT m a -> m a
- httpLbs :: MonadHttp m => Request -> m (Response ByteString)
- brConsume :: MonadHttp m => BodyReaderM m -> m [ByteString]
- data Request :: *
- data Response body :: * -> *
Class
class Monad m => MonadHttp m where #
The monad capable to do HTTP requests.
Minimal complete definition
Methods
withResponse :: Request -> (Response (BodyReaderM m) -> m a) -> m a #
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 #
Instances
MonadHttp m => MonadHttp (MaybeT m) # | |
MonadHttp m => MonadHttp (NoLoggingT m) # | |
MonadHttp m => MonadHttp (LoggingT m) # | |
(~) (* -> *) m IO => MonadHttp (HttpT m) # | TODO: Generalise to MonadIO + MonadMask? |
MonadHttp m => MonadHttp (RandT g m) # | |
(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) # | |
(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) # | |
MonadHttp m => MonadHttp (StateT r m) # | |
MonadHttp m => MonadHttp (StateT r m) # | |
(MonadHttp m, Error e) => MonadHttp (ErrorT e m) # | |
MonadHttp m => MonadHttp (ExceptT e m) # | |
MonadHttp m => MonadHttp (IdentityT * m) # | |
MonadHttp m => MonadHttp (ReaderT * r m) # | |
MonadHttp m => MonadHttp (CRandT g e m) # | |
(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) # | |
(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) # | |
type BodyReaderM m = m ByteString #
Transformer
Http monad transformer, essentially ReaderT
Manager
.
Instances
MonadTrans HttpT # | |
MonadRWS r w s m => MonadRWS r w s (HttpT m) # | |
MonadSplit g m => MonadSplit g (HttpT m) # | |
MonadCRandom e m => MonadCRandom e (HttpT m) # | |
MonadCRandomR e m => MonadCRandomR e (HttpT m) # | |
MonadError e m => MonadError e (HttpT m) # | |
MonadReader r m => MonadReader r (HttpT m) # | |
MonadState s m => MonadState s (HttpT m) # | |
MonadWriter w m => MonadWriter w (HttpT m) # | |
Monad m => Monad (HttpT m) # | |
Functor m => Functor (HttpT m) # | |
Applicative m => Applicative (HttpT m) # | |
MonadIO m => MonadIO (HttpT m) # | |
MonadRandom m => MonadRandom (HttpT m) # | |
MonadThrow m => MonadThrow (HttpT m) # | |
MonadCatch m => MonadCatch (HttpT m) # | |
MonadMask m => MonadMask (HttpT m) # | |
MonadLogger m => MonadLogger (HttpT m) # | |
MonadLoggerIO m => MonadLoggerIO (HttpT m) # | |
MonadCont m => MonadCont (HttpT m) # | |
(~) (* -> *) m IO => MonadHttp (HttpT m) # | TODO: Generalise to MonadIO + MonadMask? |
evalHttpT :: MonadIO m => HttpT m a -> m a #
Lower HttpT
with default Manager
created with tlsManagerSettings
.
Utilities
httpLbs :: MonadHttp m => Request -> m (Response ByteString) #
A convenience wrapper around withResponse
which reads in the entire
response body and immediately releases resources.
brConsume :: MonadHttp m => BodyReaderM m -> m [ByteString] #
Strictly consume all remaining chunks of data from the stream.
Re-exports
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 parseRequest
.
The constructor for this data type is not exposed. Instead, you should use
either the defaultRequest
value, or parseRequest
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 <- parseRequest "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