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

Safe HaskellNone
LanguageHaskell2010

Strelka.RequestParsing

Contents

Description

DSL for parsing the request.

Synopsis

Documentation

type Parser = RequestParser Source #

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

Errors

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

Fail with a text message.

try :: Monad m => Parser m a -> Parser m (Either Text a) Source #

Try a parser, extracting the error as Either.

Path Segments

segment :: (Monad m, LenientParser a) => Parser m a Source #

Consume the next segment of the path with an implicit lenient Attoparsec parser.

segmentWithParser :: Monad m => Parser a -> Parser m a Source #

Consume the next segment of the path with an explicit Attoparsec parser.

segmentIs :: Monad m => Text -> Parser m () Source #

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

noSegmentsLeft :: Monad m => Parser m () Source #

Fail if there's any path segments left unconsumed.

Query

query1 :: (Monad m, DefaultValue a) => Text -> Parser m a Source #

Parse the query using implicit parsers by specifying the names of parameters.

query2 :: (Monad m, DefaultValue a, DefaultValue b) => Text -> Text -> Parser m (a, b) Source #

Parse the query using implicit parsers by specifying the names of parameters.

query3 :: (Monad m, DefaultValue a, DefaultValue b, DefaultValue c) => Text -> Text -> Text -> Parser m (a, b, c) Source #

Parse the query using implicit parsers by specifying the names of parameters.

query4 :: (Monad m, DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d) => Text -> Text -> Text -> Text -> Parser m (a, b, c, d) Source #

Parse the query using implicit parsers by specifying the names of parameters.

query5 :: (Monad m, DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d, DefaultValue e) => Text -> Text -> Text -> Text -> Text -> Parser m (a, b, c, d, e) Source #

Parse the query using implicit parsers by specifying the names of parameters.

query6 :: (Monad m, DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d, DefaultValue e, DefaultValue f) => Text -> Text -> Text -> Text -> Text -> Text -> Parser m (a, b, c, d, e, f) Source #

Parse the query using implicit parsers by specifying the names of parameters.

query7 :: (Monad m, DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d, DefaultValue e, DefaultValue f, DefaultValue g) => Text -> Text -> Text -> Text -> Text -> Text -> Text -> Parser m (a, b, c, d, e, f, g) Source #

Parse the query using implicit parsers by specifying the names of parameters.

queryWithParser :: Monad m => Params a -> Parser m a Source #

Parse the request query, i.e. the URL part that is between the "?" and "#" characters, with an explicitly specified parser.

Methods

method :: Monad m => Parser m ByteString Source #

Get the request method.

methodIs :: Monad m => ByteString -> Parser m () Source #

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

methodIsGet :: Monad m => Parser m () Source #

Same as methodIs "get".

methodIsPost :: Monad m => Parser m () Source #

Same as methodIs "post".

methodIsPut :: Monad m => Parser m () Source #

Same as methodIs "put".

methodIsDelete :: Monad m => Parser m () Source #

Same as methodIs "delete".

methodIsHead :: Monad m => Parser m () Source #

Same as methodIs "head".

methodIsTrace :: Monad m => Parser m () Source #

Same as methodIs "trace".

Headers

header :: Monad m => ByteString -> Parser m ByteString Source #

Lookup a header by name in lower-case.

accepts :: Monad m => ByteString -> Parser m () Source #

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

acceptsText :: Monad m => Parser m () Source #

Same as accepts "text/plain".

acceptsHTML :: Monad m => Parser m () Source #

Same as accepts "text/html".

acceptsJSON :: Monad m => Parser m () Source #

Same as accepts "application/json".

authorization :: Monad m => Parser m (Text, Text) Source #

Parse the username and password from the basic authorization header.

Body Consumption

body :: (MonadIO m, DefaultParser a) => Parser m a Source #

Consume the request body using an implicit parser.

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

bodyWithParser :: MonadIO m => Parser a -> Parser m a Source #

Consume the request body using the explicitly specified parser.

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