| Copyright | (c) Raghu Kaippully 2020 |
|---|---|
| License | MPL-2.0 |
| Maintainer | rkaippully@gmail.com |
| Safe Haskell | None |
| Language | Haskell2010 |
WebGear.Middlewares.Params
Contents
Description
Middlewares for handling query parameters
Synopsis
- type QueryParam (name :: Symbol) val = QueryParam' Required Strict name val
- data QueryParam' (e :: Existence) (p :: ParseStyle) (name :: Symbol) val
- data ParamNotFound = ParamNotFound
- newtype ParamParseError = ParamParseError Text
- queryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam name val ': req) a
- optionalQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Optional Strict name val ': req) a
- lenientQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Required Lenient name val ': req) a
- optionalLenientQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Optional Lenient name val ': req) a
Traits
type QueryParam (name :: Symbol) val = QueryParam' Required Strict name val Source #
Capture a query parameter with a specified name and convert it
to a value of type val via FromHttpApiData.
data QueryParam' (e :: Existence) (p :: ParseStyle) (name :: Symbol) val Source #
Capture a query parameter with a specified name and convert it
to a value of type val via FromHttpApiData. The type parameter
e denotes whether the query parameter is required to be
present. The parse style parameter p determines whether the
conversion is applied strictly or leniently.
Instances
data ParamNotFound Source #
Indicates a missing query parameter
Constructors
| ParamNotFound |
Instances
| Eq ParamNotFound Source # | |
Defined in WebGear.Middlewares.Params Methods (==) :: ParamNotFound -> ParamNotFound -> Bool # (/=) :: ParamNotFound -> ParamNotFound -> Bool # | |
| Read ParamNotFound Source # | |
Defined in WebGear.Middlewares.Params Methods readsPrec :: Int -> ReadS ParamNotFound # readList :: ReadS [ParamNotFound] # | |
| Show ParamNotFound Source # | |
Defined in WebGear.Middlewares.Params Methods showsPrec :: Int -> ParamNotFound -> ShowS # show :: ParamNotFound -> String # showList :: [ParamNotFound] -> ShowS # | |
newtype ParamParseError Source #
Error in converting a query parameter
Constructors
| ParamParseError Text |
Instances
| Eq ParamParseError Source # | |
Defined in WebGear.Middlewares.Params Methods (==) :: ParamParseError -> ParamParseError -> Bool # (/=) :: ParamParseError -> ParamParseError -> Bool # | |
| Read ParamParseError Source # | |
Defined in WebGear.Middlewares.Params Methods readsPrec :: Int -> ReadS ParamParseError # readList :: ReadS [ParamParseError] # | |
| Show ParamParseError Source # | |
Defined in WebGear.Middlewares.Params Methods showsPrec :: Int -> ParamParseError -> ShowS # show :: ParamParseError -> String # showList :: [ParamParseError] -> ShowS # | |
Middlewares
queryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam name val ': req) a Source #
A middleware to extract a query parameter and convert it to a
value of type val using FromHttpApiData.
Example usage:
queryParam @"limit" @Int handler
The associated trait attribute has type val. This middleware will
respond with a 400 Bad Request response if the query parameter is
not found or could not be parsed.
optionalQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Optional Strict name val ': req) a Source #
A middleware to extract an optional query parameter and convert
it to a value of type val using FromHttpApiData.
Example usage:
optionalQueryParam @"limit" @Int handler
The associated trait attribute has type Maybe val; a Nothing
value indicates a missing param. A 400 Bad Request response is
returned if the query parameter could not be parsed.
lenientQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Required Lenient name val ': req) a Source #
A middleware to extract a query parameter and convert it to a
value of type val using FromHttpApiData.
Example usage:
lenientQueryParam @"limit" @Int handler
The associated trait attribute has type Either Text val. A 400
Bad Request reponse is returned if the query parameter is
missing. The parsing is done leniently; the trait attribute is set
to Left Text in case of parse errors or Right val on success.
optionalLenientQueryParam :: forall name val m req a. (KnownSymbol name, FromHttpApiData val, MonadRouter m) => RequestMiddleware' m req (QueryParam' Optional Lenient name val ': req) a Source #
A middleware to extract an optional query parameter and convert it
to a value of type val using FromHttpApiData.
Example usage:
optionalLenientHeader @"Content-Length" @Integer handler
The associated trait attribute has type Maybe (Either Text
val). This middleware never fails.