webgear-core-1.1.0: Composable, type-safe library to build HTTP APIs
Safe HaskellSafe-Inferred
LanguageHaskell2010

WebGear.Core.Trait.Path

Description

Middlewares related to request paths.

All the middlewares below attempt to match components of the request path. In case of a mismatch, they abandon the current handler and tries the next handler.

Synopsis

Documentation

newtype Path Source #

A path component which is literally matched against the request but discarded after that.

Constructors

Path Text 

Instances

Instances details
Trait Path Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

Associated Types

type Attribute Path Request Source #

TraitAbsence Path Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

Associated Types

type Absence Path Request Source #

type Absence Path Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

type Absence Path Request = ()
type Attribute Path Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

data PathVar (tag :: Symbol) (val :: Type) Source #

A path variable that is extracted and converted to a value of type val. The tag is usually a type-level symbol (string) to uniquely identify this variable.

Constructors

PathVar 

Instances

Instances details
Trait (PathVar tag val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

Associated Types

type Attribute (PathVar tag val) Request Source #

TraitAbsence (PathVar tag val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

Associated Types

type Absence (PathVar tag val) Request Source #

type Absence (PathVar tag val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

type Attribute (PathVar tag val) Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

type Attribute (PathVar tag val) Request = val

data PathEnd Source #

Trait to indicate that no more path components are present in the request

Constructors

PathEnd 

Instances

Instances details
Trait PathEnd Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

Associated Types

type Attribute PathEnd Request Source #

TraitAbsence PathEnd Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

Associated Types

type Absence PathEnd Request Source #

type Absence PathEnd Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

type Attribute PathEnd Request Source # 
Instance details

Defined in WebGear.Core.Trait.Path

path :: (Get h Path Request, ArrowChoice h, ArrowError RouteMismatch h) => Text -> Middleware h ts (Path ': ts) Source #

A middleware that literally matches path s.

The symbol s could contain one or more parts separated by a forward slash character. The route will be rejected if there is no match.

For example, the following code could be used to match the URL path "a/b/c" and then invoke handler:

path "a/b/c" handler

pathVar :: forall tag val h ts. (Get h (PathVar tag val) Request, ArrowChoice h, ArrowError RouteMismatch h) => Middleware h ts (PathVar tag val ': ts) Source #

A middleware that captures a path variable from a single path component.

The value captured is converted to a value of type val. The route will be rejected if the value is not found or cannot be converted.

For example, the following code could be used to read a path component as Int tagged with the symbol "objId", and then invoke handler:

pathVar @"objId" @Int handler

pathEnd :: (Get h PathEnd Request, ArrowChoice h, ArrowError RouteMismatch h) => Middleware h ts (PathEnd ': ts) Source #

A middleware that verifies that end of path is reached.

match :: QuasiQuoter Source #

Produces middleware(s) to match an optional HTTP method and some path components.

This middleware matches a prefix of path components, the remaining components can be matched by subsequent uses of match.

This quasiquoter can be used in several ways:

QuasiQuoterEquivalent Middleware
[match| /a/b/c |]path "/a/b/c"
[match| /a/b/objId:Int/d |]path "/a/b" . pathVar @"objId" @Int . path "d"
[match| GET /a/b/c |]method GET . path "/a/b/c"
[match| GET /a/b/objId:Int/d |]method GET . path "/a/b" . pathVar @"objId" @Int . path "d"

route :: QuasiQuoter Source #

Produces middleware(s) to match an optional HTTP method and the entire request path.

This middleware is intended to be used in cases where the entire path needs to be matched. Use match middleware to match only an initial portion of the path.

This quasiquoter can be used in several ways:

QuasiQuoterEquivalent Middleware
[route| /a/b/c |]path "/a/b/c" . pathEnd
[route| /a/b/objId:Int/d |]path "/a/b" . pathVar @"objId" @Int . path "d" . pathEnd
[route| GET /a/b/c |]method GET . path "/a/b/c" . pathEnd
[route| GET /a/b/objId:Int/d |]method GET . path "/a/b" . pathVar @"objId" @Int . path "d" . pathEnd)