strelka-0.4.0.1: A flexible and composable HTTP-router

Safe HaskellNone
LanguageHaskell2010

Strelka.RequestParser

Contents

Synopsis

Documentation

newtype RequestParser m a Source #

Parser of an HTTP request. Consumes path segments, analyzes

Constructors

RequestParser (ReaderT Request (StateT [Text] (ExceptT Text m)) a) 

Instances

MonadTrans RequestParser Source # 

Methods

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

Monad m => MonadError Text (RequestParser m) Source # 
Monad m => Monad (RequestParser m) Source # 

Methods

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

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

return :: a -> RequestParser m a #

fail :: String -> RequestParser m a #

Functor m => Functor (RequestParser m) Source # 

Methods

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

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

Monad m => Applicative (RequestParser m) Source # 

Methods

pure :: a -> RequestParser m a #

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

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

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

Monad m => Alternative (RequestParser m) Source # 
Monad m => MonadPlus (RequestParser m) Source # 
MonadIO m => MonadIO (RequestParser m) Source # 

Methods

liftIO :: IO a -> RequestParser m a #

run :: RequestParser m a -> Request -> [Text] -> m (Either Text (a, [Text])) Source #

Execute the parser providing a request and a list of segments.

fail :: Monad m => Text -> RequestParser m a Source #

Fail with a text message.

liftEither :: Monad m => Either Text a -> RequestParser m a Source #

Lift Either, interpreting Left as a failure.

liftMaybe :: Monad m => Maybe a -> RequestParser m a Source #

Lift Maybe, interpreting Nothing as a failure.

unliftEither :: Monad m => RequestParser m a -> RequestParser m (Either Text a) Source #

Try a parser, extracting the error as Either.

Path segments

consumeSegment :: Monad m => RequestParser m Text Source #

Consume the next segment of the path.

consumeSegmentWithParser :: Monad m => Parser a -> RequestParser m a Source #

Consume the next segment of the path with Attoparsec parser.

consumeSegmentIfIs :: Monad m => Text -> RequestParser m () Source #

Consume the next segment if it matches the provided value and fail otherwise.

ensureThatNoSegmentsIsLeft :: Monad m => RequestParser m () Source #

Fail if there's any path segments left unconsumed.

Methods

getMethod :: Monad m => RequestParser m ByteString Source #

Get the request method.

ensureThatMethodIs :: Monad m => ByteString -> RequestParser m () Source #

Ensure that the method matches the provided value in lower-case.

Headers

getHeader :: Monad m => ByteString -> RequestParser m ByteString Source #

Lookup a header by name in lower-case.

ensureThatAccepts :: Monad m => ByteString -> RequestParser m () Source #

Ensure that the request provides an Accept header, which includes the specified content type. Content type must be in lower-case.

ensureThatAcceptsJSON :: Monad m => RequestParser m () Source #

Same as ensureThatAccepts "application/json".

checkIfAccepts :: Monad m => ByteString -> RequestParser m Bool Source #

Check whether the request provides an Accept header, which includes the specified content type. Content type must be in lower-case.

getAuthorization :: Monad m => RequestParser m (Text, Text) Source #

Parse the username and password from the basic authorization header.

Params

getParam :: Monad m => ByteString -> RequestParser m (Maybe ByteString) Source #

Get a parameter's value by its name, failing if the parameter is not present.

Maybe encodes whether the value was specified, i.e. ?name=value vs ?name.

Body

consumeBody :: MonadIO m => RequestBodyConsumer a -> RequestParser m a Source #

Consume the request body using the provided RequestBodyConsumer.

NOTICE
Since the body is consumed as a stream, you can only consume it once regardless of the Alternative branching.