Safe Haskell | None |
---|---|
Language | Haskell2010 |
WebGear.Core.Trait.QueryParam
Contents
Description
Traits and middleware to handle request query parameters.
The queryParam
middleware can extract a query parameter value trait
and invoke another handler. An error handler is invoked if the parameter
is missing or the parsing fails.
The optionalQueryParam
middleware is similar but will not invoke
the error handling in case the prameter is missing. Instead, the
trait value will be set to Nothing
in that case.
The lenientQueryParam
middleware requires the parameter to be
present. But the trait attribute will be set to Left
msg
if an
error occurs while parsing it to a Haskell value. Here msg
will
indicate the error in parsing.
Finally, we have optionalLenientQueryParam
which combines the
behaviors of optionalQueryParam
and lenientQueryParam
. In this
case, the parameter extraction never fails. Missing parameters and
parse errors are indicated in the trait attribute passed to next
handler.
Synopsis
- data QueryParam (e :: Existence) (p :: ParseStyle) (name :: Symbol) val = QueryParam
- type RequiredQueryParam = QueryParam 'Required 'Strict
- type OptionalQueryParam = QueryParam 'Optional 'Strict
- data ParamNotFound = ParamNotFound
- newtype ParamParseError = ParamParseError Text
- queryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Required 'Strict name val), ArrowChoice h) => h (With Request ts, Either ParamNotFound ParamParseError) Response -> Middleware h ts (QueryParam 'Required 'Strict name val ': ts)
- optionalQueryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Optional 'Strict name val), ArrowChoice h) => h (With Request ts, ParamParseError) Response -> Middleware h ts (QueryParam 'Optional 'Strict name val ': ts)
- lenientQueryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Required 'Lenient name val), ArrowChoice h) => h (With Request ts, ParamNotFound) Response -> Middleware h ts (QueryParam 'Required 'Lenient name val ': ts)
- optionalLenientQueryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Optional 'Lenient name val), ArrowChoice h) => Middleware h ts (QueryParam 'Optional 'Lenient name val ': ts)
Traits
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
. 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.
Constructors
QueryParam |
Instances
type Absence (QueryParam 'Optional 'Lenient name val) Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Absence (QueryParam 'Optional 'Strict name val) Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Absence (QueryParam 'Required 'Lenient name val) Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Absence (QueryParam 'Required 'Strict name val) Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Attribute (QueryParam 'Optional 'Lenient name val) Request Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Attribute (QueryParam 'Optional 'Strict name val) Request Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Attribute (QueryParam 'Required 'Lenient name val) Request Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Attribute (QueryParam 'Required 'Strict name val) Request Source # | |
Defined in WebGear.Core.Trait.QueryParam | |
type Prerequisite (QueryParam e p name val) ts Source # | |
Defined in WebGear.Core.Trait.QueryParam |
type RequiredQueryParam = QueryParam 'Required 'Strict Source #
QueryParam
that is required and parsed strictly
type OptionalQueryParam = QueryParam 'Optional 'Strict Source #
QueryParam
that is optional and parsed strictly
data ParamNotFound Source #
Indicates a missing query parameter
Constructors
ParamNotFound |
Instances
Read ParamNotFound Source # | |
Defined in WebGear.Core.Trait.QueryParam Methods readsPrec :: Int -> ReadS ParamNotFound # readList :: ReadS [ParamNotFound] # | |
Show ParamNotFound Source # | |
Defined in WebGear.Core.Trait.QueryParam Methods showsPrec :: Int -> ParamNotFound -> ShowS # show :: ParamNotFound -> String # showList :: [ParamNotFound] -> ShowS # | |
Eq ParamNotFound Source # | |
Defined in WebGear.Core.Trait.QueryParam Methods (==) :: ParamNotFound -> ParamNotFound -> Bool # (/=) :: ParamNotFound -> ParamNotFound -> Bool # |
newtype ParamParseError Source #
Error in converting a query parameter
Constructors
ParamParseError Text |
Instances
Read ParamParseError Source # | |
Defined in WebGear.Core.Trait.QueryParam Methods readsPrec :: Int -> ReadS ParamParseError # readList :: ReadS [ParamParseError] # | |
Show ParamParseError Source # | |
Defined in WebGear.Core.Trait.QueryParam Methods showsPrec :: Int -> ParamParseError -> ShowS # show :: ParamParseError -> String # showList :: [ParamParseError] -> ShowS # | |
Eq ParamParseError Source # | |
Defined in WebGear.Core.Trait.QueryParam Methods (==) :: ParamParseError -> ParamParseError -> Bool # (/=) :: ParamParseError -> ParamParseError -> Bool # |
Middlewares
queryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Required 'Strict name val), ArrowChoice h) => h (With Request ts, Either ParamNotFound ParamParseError) Response -> Middleware h ts (QueryParam 'Required 'Strict name val ': ts) Source #
Extract a query parameter and convert it to a value of type
val
.
The associated trait attribute has type val
.
Example usage:
queryParam @"limit" @Integer errorHandler okHandler
optionalQueryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Optional 'Strict name val), ArrowChoice h) => h (With Request ts, ParamParseError) Response -> Middleware h ts (QueryParam 'Optional 'Strict name val ': ts) Source #
Extract an optional query parameter and convert it to a value of
type val
.
The associated trait attribute has type Maybe val
; a Nothing
value indicates that the parameter is missing from the request.
Example usage:
optionalQueryParam @"limit" @Integer errorHandler okHandler
lenientQueryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Required 'Lenient name val), ArrowChoice h) => h (With Request ts, ParamNotFound) Response -> Middleware h ts (QueryParam 'Required 'Lenient name val ': ts) Source #
Extract a query parameter and convert it to a value of type val
.
The associated trait attribute has type Either Text val
. The
parsing is done leniently and any errors are reported in the trait
attribute.
Example usage:
lenientQueryParam @"limit" @Integer errorHandler okHandler
optionalLenientQueryParam :: forall (name :: Symbol) val h (ts :: [Type]). (Get h (QueryParam 'Optional 'Lenient name val), ArrowChoice h) => Middleware h ts (QueryParam 'Optional 'Lenient name val ': ts) Source #
Extract a query parameter and convert it to a value of type val
.
Example usage:
optionalLenientQueryParam @"Content-Length" @Integer handler
The associated trait attribute has type Maybe (Either Text
val)
. The parsing is done leniently. Any parsing errors and
missing query parameters are reported in the trait attribute.