wai-middleware-route-0.5.0: Wai dispatch middleware

Safe HaskellSafe-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.


Routing rules

data Rule Source

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 Pieces 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 Pieces. The same thing happens with the slashes at the ends of paths.
 [Static "foo"]
 [Static "foo", Static "bar"]
 [Static "foo", Dynamic, Static "bar"]
 [Dynamic, Static "foo", Dynamic, Static "bar", Static "baz", Dynamic]


Get Text Application

GET, fixed length path

Post Text Application

POST, fixed length path

Head Text Application

HEAD, fixed length path

Put Text Application

PUT, fixed length path

Delete Text Application

DELETE, fixed length path

Trace Text Application

TRACE, fixed length path

Connect Text Application

CONNECT, fixed length path

Options Text Application

OPTIONS, fixed length path

Any Text Application

Any HTTP method, fixed length path

Get' Text Application

GET, variable length path

Post' Text Application

POST, variable length path

Head' Text Application

HEAD, variable length path

Put' Text Application

PUT, variable length path

Delete' Text Application

DELETE, variable length path

Trace' Text Application

TRACE, variable length path

Connect' Text Application

CONNECT, variable length path

Options' Text Application

OPTIONS, variable length path

Any' Text Application

Any HTTP method, variable length path

Gen Bool Text Text Application

Generic rule with path lenghts flag, HTTP method and path



:: [Rule]

Routing rules

-> [Route Application] 

Make Routes from Rules.

Equivalent map mkRoute

mkRoutes' :: [Rule] -> Dispatch ApplicationSource

Make Dispatchs from Rules.

Equivalent toDispatch . mkRoutes

mkRoute :: Rule -> Route ApplicationSource

Make Route from Rule. rhPieces of Route will be prepended with Piece with corresponding HTTP method. Static means concrete method. Dynamic means any method.

 mkRoute $ Get "foo/bar" app
 Route [Static "foo", Static "bar"] False (const $ Just app) 




:: Dispatch Application

Dispatch function. Use toDispatch and route helpers below.

-> Application

Default (404) application.

-> 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")