strelka-1: A simple, flexible and composable web-router

Safe HaskellNone
LanguageHaskell2010

Strelka.RequestParser

Contents

Description

DSL for parsing the request.

Synopsis

Documentation

type RequestParser = RequestParser Source #

Parser of an HTTP request. Analyzes its meta information, consumes the path segments and the body.

Errors

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.

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 a value was specified at all, i.e. ?name=value vs ?name.

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.

Body Consumption

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.