Safe Haskell | Safe-Infered |
---|
Network.Wai.Middleware.Route
Contents
Description
This module contains helpers for use Yesod.Routes.Dispatch with Network.Wai.
This Middleware
uses first Piece
in path to route HTTP
method.
Static
means concrete method. Dynamic
means any method.
- data Rule
- = Get Text Application
- | Post Text Application
- | Head Text Application
- | Put Text Application
- | Delete Text Application
- | Trace Text Application
- | Connect Text Application
- | Options Text Application
- | Any Text Application
- | Get' Text Application
- | Post' Text Application
- | Head' Text Application
- | Put' Text Application
- | Delete' Text Application
- | Trace' Text Application
- | Connect' Text Application
- | Options' Text Application
- | Any' Text Application
- | Gen Bool Text Text Application
- mkRoutes :: [Rule] -> [Route Application]
- mkRoutes' :: [Rule] -> Dispatch Application
- mkRoute :: Rule -> Route Application
- dispatch :: Dispatch Application -> Application -> Application
Routing rules
Rule for route. Rules without single quotes ('
) means fixed length
paths. And vice versa, rules with single quotes ('
) means paths with
variable lengh
Paths converts to Piece
s by following rules:
- Paths splits by slashes (
/
). - Text between slashes becomes
Static
Piece
. The same thing happens with the text at the ends of paths. - Double (triple, etc.) slashes means becomes
Dynamic
Piece
s. The same thing happens with the slashes at the ends of paths.
"foo" [Static "foo"] "foo/bar" [Static "foo", Static "bar"] "foo//bar" [Static "foo", Dynamic, Static "bar"] "/foo//bar/baz/" [Dynamic, Static "foo", Dynamic, Static "bar", Static "baz", Dynamic]
Constructors
Get Text Application |
|
Post Text Application |
|
Head Text Application |
|
Put Text Application |
|
Delete Text Application |
|
Trace Text Application |
|
Connect Text Application |
|
Options Text Application |
|
Any Text Application | Any |
Get' Text Application |
|
Post' Text Application |
|
Head' Text Application |
|
Put' Text Application |
|
Delete' Text Application |
|
Trace' Text Application |
|
Connect' Text Application |
|
Options' Text Application |
|
Any' Text Application | Any |
Gen Bool Text Text Application | Generic rule with path lenghts flag, |
Arguments
:: [Rule] | Routing rules |
-> [Route Application] |
Make Route
s from Rules
.
Equivalent map mkRoute
mkRoutes' :: [Rule] -> Dispatch ApplicationSource
Make Dispatch
s from Rules
.
Equivalent toDispatch . mkRoutes
mkRoute :: Rule -> Route ApplicationSource
Middleware
Arguments
:: Dispatch Application | Dispatch function.
Use |
-> Application | Default ( |
-> Application |
Dispatch function.
rs :: Dispatch Application rs = toDispatch . mkRoutes [ Get "foo" fooGetApp , Post "foo" fooPostApp , Get "foo//bar" fooDynBarApp , Any "any" anyMethodApp ] app :: Application app = dispatch rs (error "Not dispatched")