Safe Haskell | Safe-Infered |
---|
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
- | Gen 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. - Hashes (
#
) inside slashes becomesDynamic
Piece
s. - To make route with variable length just add asterisk (
*
) after last slash.
"foo" [Static "foo"] Fixed "foo/bar" [Static "foo", Static "bar"] Fixed "foo/#/bar" [Static "foo", Dynamic, Static "bar"] Fixed "foo/#/bar/baz/*" [Dynamic, Static "foo", Dynamic, Static "bar", Static "baz"] Variable
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 Text Text Application | Generic rule with |
:: [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
:: 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")