wai-middleware-route-0.7.3: Wai dispatch middleware

Safe HaskellNone

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.
  • Hashes (#) inside slashes becomes Dynamic Pieces.
  • 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

Constructors

Get Text Application

GET method

Post Text Application

POST method

Head Text Application

HEAD method

Put Text Application

PUT method

Delete Text Application

DELETE method

Trace Text Application

TRACE method

Connect Text Application

CONNECT method

Options Text Application

OPTIONS method

Any Text Application

Any HTTP method

Gen Text Text Application

Generic rule with 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

:: Bool

Squash empty pathInfo chunks. It often appear in the presence of double slashes or "Ending slash" in URL.

-> Dispatch Application

Dispatch function. Use toDispatch and route helpers.

-> Application

Default (404) application.

-> Application 

Dispatch Middleware.

 rs :: Dispatch Application
 rs = toDispatch . mkRoutes [
      Get  "foo"  fooGetApp
    , Post "foo"  fooPostApp
    , Get "foo//bar" fooDynBarApp
 
    , Any  "any"  anyMethodApp
    ]
 
 app :: Application
 app = dispatch True rs (error "Not dispatched")

dispatch_Source

Arguments

:: Dispatch Application

Dispatch function. Use toDispatch and route helpers.

-> Application

Default (404) application.

-> Application