webgear-core-1.4.0: Composable, type-safe library to build HTTP APIs
Safe HaskellNone
LanguageHaskell2010

WebGear.Core.Trait.QueryParam

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

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

Instances details
type Absence (QueryParam 'Optional 'Lenient name val) Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Absence (QueryParam 'Optional 'Lenient name val) = Void
type Absence (QueryParam 'Optional 'Strict name val) Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Absence (QueryParam 'Required 'Lenient name val) Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Absence (QueryParam 'Required 'Strict name val) Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Attribute (QueryParam 'Optional 'Lenient name val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Attribute (QueryParam 'Optional 'Strict name val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Attribute (QueryParam 'Required 'Lenient name val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Attribute (QueryParam 'Required 'Strict name val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Attribute (QueryParam 'Required 'Strict name val) Request = val
type Prerequisite (QueryParam e p name val) ts Source # 
Instance details

Defined in WebGear.Core.Trait.QueryParam

type Prerequisite (QueryParam e p name val) ts = ()

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

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.