webgear-core-1.3.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
type Absence Path Source # 
Instance details

Defined in WebGear.Core.Trait.Path

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

Defined in WebGear.Core.Trait.Path

type Prerequisite Path ts Source # 
Instance details

Defined in WebGear.Core.Trait.Path

type Prerequisite Path ts = ()

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
type Absence (PathVar tag val) Source # 
Instance details

Defined in WebGear.Core.Trait.Path

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

Defined in WebGear.Core.Trait.Path

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

Defined in WebGear.Core.Trait.Path

type Prerequisite (PathVar tag val) ts = ()

data PathEnd Source #

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

Constructors

PathEnd 

Instances

Instances details
type Absence PathEnd Source # 
Instance details

Defined in WebGear.Core.Trait.Path

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

Defined in WebGear.Core.Trait.Path

type Prerequisite PathEnd ts Source # 
Instance details

Defined in WebGear.Core.Trait.Path

type Prerequisite PathEnd ts = ()

path :: (Get h Path, 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), 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, 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)