wai-middleware-route-0.5.1: Wai dispatch middleware

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

Synopsis

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

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

mkRoutesSource

Arguments

:: [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) 

Middleware

dispatchSource

Arguments

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