Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- newtype Path = Path Text
- data PathVar (tag :: Symbol) (val :: Type) = PathVar
- data PathVarError
- data PathEnd = PathEnd
- path :: (Get h Path Request, ArrowChoice h, ArrowError RouteMismatch h) => Text -> Middleware h req (Path ': req)
- pathVar :: forall tag val h req. (Get h (PathVar tag val) Request, ArrowChoice h, ArrowError RouteMismatch h) => Middleware h req (PathVar tag val ': req)
- pathEnd :: (Get h PathEnd Request, ArrowChoice h, ArrowError RouteMismatch h) => Middleware h req (PathEnd ': req)
- match :: QuasiQuoter
- route :: QuasiQuoter
Documentation
A path component which is literally matched against the request but discarded after that.
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.
data PathVarError Source #
Failure to extract a PathVar
Instances
Eq PathVarError Source # | |
Defined in WebGear.Core.Trait.Path (==) :: PathVarError -> PathVarError -> Bool # (/=) :: PathVarError -> PathVarError -> Bool # | |
Read PathVarError Source # | |
Defined in WebGear.Core.Trait.Path readsPrec :: Int -> ReadS PathVarError # readList :: ReadS [PathVarError] # | |
Show PathVarError Source # | |
Defined in WebGear.Core.Trait.Path showsPrec :: Int -> PathVarError -> ShowS # show :: PathVarError -> String # showList :: [PathVarError] -> ShowS # |
Trait to indicate that no more path components are present in the request
path :: (Get h Path Request, ArrowChoice h, ArrowError RouteMismatch h) => Text -> Middleware h req (Path ': req) 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 req. (Get h (PathVar tag val) Request, ArrowChoice h, ArrowError RouteMismatch h) => Middleware h req (PathVar tag val ': req) 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 req (PathEnd ': req) 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:
QuasiQuoter | Equivalent Middleware |
---|---|
[match| /a/b/c |] |
|
[match| /a/b/objId:Int/d |] |
|
[match| GET /a/b/c |] |
|
[match| GET /a/b/objId:Int/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:
QuasiQuoter | Equivalent Middleware |
---|---|
[route| /a/b/c |] |
|
[route| /a/b/objId:Int/d |] |
|
[route| GET /a/b/c |] |
|
[route| GET /a/b/objId:Int/d |] |
|