| Copyright | (c) Raghu Kaippully 2020 |
|---|---|
| License | MPL-2.0 |
| Maintainer | rkaippully@gmail.com |
| Safe Haskell | None |
| Language | Haskell2010 |
WebGear.Middlewares.Path
Description
Middlewares related to route paths.
Synopsis
- path :: forall s ts res m a. (KnownSymbol s, MonadRouter m) => RequestMiddleware m ts (Path s ': ts) res a
- pathVar :: forall tag val ts res m a. (FromHttpApiData val, MonadRouter m) => RequestMiddleware m ts (PathVar tag val ': ts) res a
- match :: QuasiQuoter
Documentation
path :: forall s ts res m a. (KnownSymbol s, MonadRouter m) => RequestMiddleware m ts (Path s ': ts) res a 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 ts res m a. (FromHttpApiData val, MonadRouter m) => RequestMiddleware m ts (PathVar tag val ': ts) res a Source #
A middleware that captures a path variable from a single path component.
The value captured is converted to a value of type val via
FromHttpApiData. 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
match :: QuasiQuoter Source #
Produces middleware(s) to match an optional HTTP method and path.
This quasiquoter can be used in several ways:
[match|a/b/c]is equivalent topath@"a/b/c"[match|a/b/objId:Int/d]is equivalent to"d"@path@"a/b" .pathVar@"objId" @Int .path[match|GET a/b/c]is equivalent tomethod@GET $path@"a/b/c"[match|GET a/b/objId:Int/d]is equivalent tomethod@GET .path@"a/b" .pathVar@"objId" @Int .path@"d"