wai-routes-0.3.4: Typesafe URLs for Wai applications.

Portabilitynon-portable (uses ghc extensions)
Stabilityexperimental
Maintainerajnsit@gmail.com
Safe HaskellNone

Network.Wai.Middleware.Routes

Contents

Description

This package provides typesafe URLs for Wai applications.

Synopsis

Quasi Quoters

parseRoutes :: QuasiQuoter

A quasi-quoter to parse a string into a list of Resources. Checks for overlapping routes, failing if present; use parseRoutesNoCheck to skip the checking. See documentation site for details on syntax.

Parse Routes declared inline

Parse routes declared in a file

parseRoutesNoCheck :: QuasiQuoter

Same as parseRoutes, but performs no overlap checking.

Parse routes declared inline, without checking for overlaps

Parse routes declared in a file, without checking for overlaps

Template Haskell methods

mkRoute :: String -> [ResourceTree String] -> Q [Dec]Source

Generates all the things needed for efficient routing, including your application's Route datatype, and RenderRoute, ParseRoute, and RouteAttr instances

Dispatch

routeDispatch :: Routable master => master -> MiddlewareSource

Generates the application middleware from a Routable master datatype

URL rendering and parsing

showRoute :: RenderRoute master => Route master -> TextSource

Renders a Route as Text

readRoute :: ParseRoute master => Text -> Maybe (Route master)Source

Read a route from Text Returns Nothing if Route reading failed. Just route otherwise

Application Handlers

type Handler master = master -> RequestData -> ResourceT IO ResponseSource

A Handler generates an App from the master datatype

Generated Datatypes

class Routable master whereSource

A Routable instance can be used in dispatching. An appropriate instance for your site datatype is automatically generated by mkRoute

Methods

dispatcher :: Handler masterSource

Used internally. However needs to be exported for TH to work.

class Eq (Route a) => RenderRoute a where

Associated Types

data Route a1

The type-safe URLs associated with a site argument.

Methods

renderRoute :: Route a -> ([Text], [(Text, Text)])

A RenderRoute instance for your site datatype is automatically generated by mkRoute

class RenderRoute a => ParseRoute a where

Methods

parseRoute :: ([Text], [(Text, Text)]) -> Maybe (Route a)

A ParseRoute instance for your site datatype is automatically generated by mkRoute

class RenderRoute a => RouteAttrs a where

Methods

routeAttrs :: Route a -> Set Text

A RouteAttrs instance for your site datatype is automatically generated by mkRoute

Accessing Raw Request Data

An abstract representation of the request data. You can get the wai request object by using waiReq

Extract the wai Request object from RequestData

Extract the next Application in the stack

runNext :: RequestData -> ResourceT IO ResponseSource

Run the next application in the stack

Run the next application in the stack

Route Monad makes it easy to compose routes together

data RouteM a Source

The Route Monad

Instances

defaultAction :: Application -> RouteM ()Source

Set the default action of the Application. You should only call this once in an application. Subsequent invocations override the previous settings.

Set the default action for a app

middleware :: Middleware -> RouteM ()Source

Add a middleware to the application. Middleware is nested so the one declared earlier is outer.

Add another middleware to the app

route :: Routable master => master -> RouteM ()Source

Add a route to the application. Routes are ordered so the one declared earlier is matched first.

Add another routed middleware to the app

toWaiApp :: RouteM () -> IO ApplicationSource

Convert a RouteM Monadic value into a wai application.

Convert a RouteM to a wai Application

HandlerM Monad makes it easy to build a handler

data HandlerM master a Source

The HandlerM Monad

Instances

Monad (HandlerM master) 
Functor (HandlerM master) 
MonadIO (HandlerM master) 

runHandlerM :: HandlerM master Response -> Handler masterSource

Run HandlerM, resulting in a Handler

Run a HandlerM to get a Handler

liftResourceT :: ResourceT IO a -> HandlerM master aSource

Lift a ResourceT into HandlerM

Lift a ResourceT into HandlerM

request :: HandlerM master RequestSource

Get the request

Access the request data

master :: HandlerM master masterSource

Get the master

Access the master datatype

next :: HandlerM master ResponseSource

Run the next application

Run the next application in the stack