wai-middleware-route-0.3.0: Wai routing middleware

Network.Wai.Middleware.Route

Contents

Description

Route middleware for wai.

It's Heavy inspired by vhost middleware from wai-extra but gives some sugar to life.

Synopsis

Dispatching

dispatchSource

Arguments

:: [(Request -> Bool, Application)]

List of routes

-> Application

Default Application

-> Application

Returns founded Application. If not found - returns default.

Dispatch. Seek for first route where the "rule" gives a positive result. Uses find instead filter in vhost

 dispatch [
     ((=="/") . rawPathInfo, auth . cache . Issues.get)
   , ((=="/issues") . rawPathInfo, cache . About.handle)
   ] defaultApp

Creating rules

onRegexSource

Arguments

:: Method

HTTP Method. Use "*" for any method

-> ByteString

Request path pattern.

-> Request

Request

-> Bool 

Most frequently case: HTTP Method and Request path regex pattern.

 ("*" `rule` "^/issue/", app)
 (methodGet `rule` "^/issues$", anotherApp)

onPrefixSource

Arguments

:: Method

HTTP Method. Use "*" for any method

-> ByteString

Request path prefix.

-> Request

Request

-> Bool

Routing rule

HTTP Method and Request path prefix.

 ("*" `rule` "^/issue/", app)
 (methodGet `rule` "^/issues$", anotherApp)

onExactSource

Arguments

:: Method

HTTP Method. Use "*" for any method

-> ByteString

Request path.

-> Request

Request

-> Bool

Routing rule

HTTP Method and Request path.

 ("*" `rule` "^/issue/", app)
 (methodGet `rule` "^/issues$", anotherApp)