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 #

The monad capable to do HTTP requests.

Minimal complete definition

withResponse

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) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (RandT g m)) -> RandT g m a) -> RandT g m a #

brRead :: BodyReaderM (RandT g m) -> RandT g m ByteString #

(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (WriterT w m)) -> WriterT w m a) -> WriterT w m a #

brRead :: BodyReaderM (WriterT w m) -> WriterT w m ByteString #

(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (WriterT w m)) -> WriterT w m a) -> WriterT w m a #

brRead :: BodyReaderM (WriterT w m) -> WriterT w m ByteString #

MonadHttp m => MonadHttp (StateT r m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (StateT r m)) -> StateT r m a) -> StateT r m a #

brRead :: BodyReaderM (StateT r m) -> StateT r m ByteString #

MonadHttp m => MonadHttp (StateT r m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (StateT r m)) -> StateT r m a) -> StateT r m a #

brRead :: BodyReaderM (StateT r m) -> StateT r m ByteString #

(MonadHttp m, Error e) => MonadHttp (ErrorT e m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (ErrorT e m)) -> ErrorT e m a) -> ErrorT e m a #

brRead :: BodyReaderM (ErrorT e m) -> ErrorT e m ByteString #

MonadHttp m => MonadHttp (ExceptT e m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (ExceptT e m)) -> ExceptT e m a) -> ExceptT e m a #

brRead :: BodyReaderM (ExceptT e m) -> ExceptT e m ByteString #

MonadHttp m => MonadHttp (IdentityT * m) # 
MonadHttp m => MonadHttp (ReaderT * r m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (ReaderT * r m)) -> ReaderT * r m a) -> ReaderT * r m a #

brRead :: BodyReaderM (ReaderT * r m) -> ReaderT * r m ByteString #

MonadHttp m => MonadHttp (CRandT g e m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (CRandT g e m)) -> CRandT g e m a) -> CRandT g e m a #

brRead :: BodyReaderM (CRandT g e m) -> CRandT g e m ByteString #

(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (RWST r w s m)) -> RWST r w s m a) -> RWST r w s m a #

brRead :: BodyReaderM (RWST r w s m) -> RWST r w s m ByteString #

(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) # 

Methods

withResponse :: Request -> (Response (BodyReaderM (RWST r w s m)) -> RWST r w s m a) -> RWST r w s m a #

brRead :: BodyReaderM (RWST r w s m) -> RWST r w s m ByteString #

Transformer

newtype HttpT m a #

Http monad transformer, essentially ReaderT Manager.

Constructors

HttpT 

Fields

Instances

MonadTrans HttpT # 

Methods

lift :: Monad m => m a -> HttpT m a #

MonadRWS r w s m => MonadRWS r w s (HttpT m) # 
MonadSplit g m => MonadSplit g (HttpT m) # 

Methods

getSplit :: HttpT m g #

MonadCRandom e m => MonadCRandom e (HttpT m) # 
MonadCRandomR e m => MonadCRandomR e (HttpT m) # 

Methods

getCRandomR :: CRandomR a => (a, a) -> HttpT m a #

MonadError e m => MonadError e (HttpT m) # 

Methods

throwError :: e -> HttpT m a #

catchError :: HttpT m a -> (e -> HttpT m a) -> HttpT m a #

MonadReader r m => MonadReader r (HttpT m) # 

Methods

ask :: HttpT m r #

local :: (r -> r) -> HttpT m a -> HttpT m a #

reader :: (r -> a) -> HttpT m a #

MonadState s m => MonadState s (HttpT m) # 

Methods

get :: HttpT m s #

put :: s -> HttpT m () #

state :: (s -> (a, s)) -> HttpT m a #

MonadWriter w m => MonadWriter w (HttpT m) # 

Methods

writer :: (a, w) -> HttpT m a #

tell :: w -> HttpT m () #

listen :: HttpT m a -> HttpT m (a, w) #

pass :: HttpT m (a, w -> w) -> HttpT m a #

Monad m => Monad (HttpT m) # 

Methods

(>>=) :: HttpT m a -> (a -> HttpT m b) -> HttpT m b #

(>>) :: HttpT m a -> HttpT m b -> HttpT m b #

return :: a -> HttpT m a #

fail :: String -> HttpT m a #

Functor m => Functor (HttpT m) # 

Methods

fmap :: (a -> b) -> HttpT m a -> HttpT m b #

(<$) :: a -> HttpT m b -> HttpT m a #

Applicative m => Applicative (HttpT m) # 

Methods

pure :: a -> HttpT m a #

(<*>) :: HttpT m (a -> b) -> HttpT m a -> HttpT m b #

(*>) :: HttpT m a -> HttpT m b -> HttpT m b #

(<*) :: HttpT m a -> HttpT m b -> HttpT m a #

MonadIO m => MonadIO (HttpT m) # 

Methods

liftIO :: IO a -> HttpT m a #

MonadRandom m => MonadRandom (HttpT m) # 

Methods

getRandomR :: Random a => (a, a) -> HttpT m a #

getRandom :: Random a => HttpT m a #

getRandomRs :: Random a => (a, a) -> HttpT m [a] #

getRandoms :: Random a => HttpT m [a] #

MonadThrow m => MonadThrow (HttpT m) # 

Methods

throwM :: Exception e => e -> HttpT m a #

MonadCatch m => MonadCatch (HttpT m) # 

Methods

catch :: Exception e => HttpT m a -> (e -> HttpT m a) -> HttpT m a #

MonadMask m => MonadMask (HttpT m) # 

Methods

mask :: ((forall a. HttpT m a -> HttpT m a) -> HttpT m b) -> HttpT m b #

uninterruptibleMask :: ((forall a. HttpT m a -> HttpT m a) -> HttpT m b) -> HttpT m b #

MonadLogger m => MonadLogger (HttpT m) # 

Methods

monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> HttpT m () #

MonadLoggerIO m => MonadLoggerIO (HttpT m) # 

Methods

askLoggerIO :: HttpT m (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) #

MonadCont m => MonadCont (HttpT m) # 

Methods

callCC :: ((a -> HttpT m b) -> HttpT m a) -> HttpT m a #

(~) (* -> *) 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

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 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

Instances

data Response body :: * -> * #

A simple representation of the HTTP response.

Since 0.1.0

Instances

Functor Response 

Methods

fmap :: (a -> b) -> Response a -> Response b #

(<$) :: a -> Response b -> Response a #

Foldable Response 

Methods

fold :: Monoid m => Response m -> m #

foldMap :: Monoid m => (a -> m) -> Response a -> m #

foldr :: (a -> b -> b) -> b -> Response a -> b #

foldr' :: (a -> b -> b) -> b -> Response a -> b #

foldl :: (b -> a -> b) -> b -> Response a -> b #

foldl' :: (b -> a -> b) -> b -> Response a -> b #

foldr1 :: (a -> a -> a) -> Response a -> a #

foldl1 :: (a -> a -> a) -> Response a -> a #

toList :: Response a -> [a] #

null :: Response a -> Bool #

length :: Response a -> Int #

elem :: Eq a => a -> Response a -> Bool #

maximum :: Ord a => Response a -> a #

minimum :: Ord a => Response a -> a #

sum :: Num a => Response a -> a #

product :: Num a => Response a -> a #

Traversable Response 

Methods

traverse :: Applicative f => (a -> f b) -> Response a -> f (Response b) #

sequenceA :: Applicative f => Response (f a) -> f (Response a) #

mapM :: Monad m => (a -> m b) -> Response a -> m (Response b) #

sequence :: Monad m => Response (m a) -> m (Response a) #

Eq body => Eq (Response body) 

Methods

(==) :: Response body -> Response body -> Bool #

(/=) :: Response body -> Response body -> Bool #

Show body => Show (Response body) 

Methods

showsPrec :: Int -> Response body -> ShowS #

show :: Response body -> String #

showList :: [Response body] -> ShowS #