wai-middleware-route-0.4.0: 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

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 [
      -- simple paths 
      sGET  "foo"  fooGetApp
    , sPOST "foo"  fooPostApp
    , sGET  "foo/" fooGetDynApp
 
      -- native paths
    , sGET'  [Static "bar", Dynamic] barGetDynApp

      -- simple paths, any method 
    , sANY  "any"  anyMethodApp
    ]
 
 app :: Application
 app = dispatch rs (error "Not dispatched")

Route helpers

Functions below simplify process of creating Routes. Each helper prepends corresponding HTTP method to path.

Simple paths

All functions below is combinations of native path helpers and mkP.

Fixed length

sGET,sOPTIONS,sCONNECT,sTRACE,sDELETE,sPUT,sHEAD,sPOSTSource

Arguments

:: Text

Path

-> Application

Routable application

-> Route Application 

Route helpers for concrete HTTP methods with fixed-length simple path.

sANYSource

Arguments

:: Text

Path

-> Application

Routable application

-> Route Application 

Route helper for any HTTP method with fixed-length simple path.

Variable length

mGET,mOPTIONS,mCONNECT,mTRACE,mDELETE,mPUT,mHEAD,mPOSTSource

Arguments

:: Text

Path

-> Application

Routable application

-> Route Application 

Route helpers for concrete HTTP methods with vary-length simple path.

mANYSource

Arguments

:: Text

Path

-> Application

Routable application

-> Route Application 

Route helper for any HTTP method with vary-length simple path.

Native paths

Fixed length

sGET',sOPTIONS',sCONNECT',sTRACE',sDELETE',sPUT',sHEAD',sPOST'Source

Arguments

:: [Piece]

Path

-> Application

Routable application

-> Route Application 

Route helpers for concrete HTTP methods with fixed-length native yesod-routes path.

sANY'Source

Arguments

:: [Piece]

Path

-> Application

Routable application

-> Route Application 

Route helper for any HTTP method with fixed-length native yesod-routes path.

sRouteSource

Arguments

:: Piece

Method piece. Dynamic means any method.

-> [Piece]

Path pieces

-> Application

Routed application

-> Route Application 

Generalized Route helper for fixed-length native yesod-routes path.

Variable length

mGET',mOPTIONS',mCONNECT',mTRACE',mDELETE',mPUT',mHEAD',mPOST'Source

Arguments

:: [Piece]

Path

-> Application

Routable application

-> Route Application 

Route helpers for concrete HTTP methods with vary-length native yesod-routes path.

mANY'Source

Arguments

:: [Piece]

Path

-> Application

Routable application

-> Route Application 

Route helper for any HTTP method with fixed-length native yesod-routes path.

mRouteSource

Arguments

:: Piece

Method piece. Dynamic means any method.

-> [Piece]

Path pieces

-> Application

Routed application

-> Route Application 

Generalized Route helper for vary-length native yesod-routes path.

Piece helper

mkP :: Text -> [Piece]Source

Make Pieces from Text. Splits path on slashes. Dual slashes means Dynamic Pieces.

 mkP ""             -- []
 mkP "foo/bar"      -- [Static "foo", Static "bar"]
 mkP "foo//bar/"    -- [Static "foo", Dynamic, Static "bar", Dynamic]