Copyright | (c) Raghu Kaippully 2020 |
---|---|
License | MPL-2.0 |
Maintainer | rkaippully@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Middlewares related to route paths.
Synopsis
- data Path (s :: Symbol)
- data PathVar tag val
- data PathVarError
- data PathEnd
- path :: forall s ts m a. (KnownSymbol s, MonadRouter m) => RequestMiddleware' m ts (Path s ': ts) a
- pathVar :: forall tag val ts m a. (FromHttpApiData val, MonadRouter m) => RequestMiddleware' m ts (PathVar tag val ': ts) a
- pathEnd :: MonadRouter m => RequestMiddleware' m ts (PathEnd ': ts) a
- match :: QuasiQuoter
- route :: QuasiQuoter
Documentation
data Path (s :: Symbol) Source #
A path component which is literally matched against the request but discarded after that.
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.Middlewares.Path (==) :: PathVarError -> PathVarError -> Bool # (/=) :: PathVarError -> PathVarError -> Bool # | |
Read PathVarError Source # | |
Defined in WebGear.Middlewares.Path readsPrec :: Int -> ReadS PathVarError # readList :: ReadS [PathVarError] # | |
Show PathVarError Source # | |
Defined in WebGear.Middlewares.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 :: forall s ts m a. (KnownSymbol s, MonadRouter m) => RequestMiddleware' m ts (Path s ': ts) 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 m a. (FromHttpApiData val, MonadRouter m) => RequestMiddleware' m ts (PathVar tag val ': ts) 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
pathEnd :: MonadRouter m => RequestMiddleware' m ts (PathEnd ': ts) a 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 |] |
|