| Copyright | (c) Anupam Jain 2013 |
|---|---|
| License | MIT (see the file LICENSE) |
| Maintainer | ajnsit@gmail.com |
| Stability | experimental |
| Portability | non-portable (uses ghc extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
Network.Wai.Middleware.Routes.Routes
Contents
Description
This package provides typesafe URLs for Wai applications.
- parseRoutes :: QuasiQuoter
- parseRoutesFile :: FilePath -> Q Exp
- parseRoutesNoCheck :: QuasiQuoter
- parseRoutesFileNoCheck :: FilePath -> Q Exp
- mkRoute :: String -> [ResourceTree String] -> Q [Dec]
- routeDispatch :: Routable master => master -> Middleware
- showRoute :: RenderRoute master => Route master -> Text
- readRoute :: ParseRoute master => Text -> Maybe (Route master)
- type Handler master = master -> RequestData -> ResponseHandler
- type ResponseHandler = (Response -> IO ResponseReceived) -> IO ResponseReceived
- class Routable master where
- dispatcher :: Handler master
- class Eq (Route a) => RenderRoute a where
- class RenderRoute a => ParseRoute a where
- class RenderRoute a => RouteAttrs a where
- routeAttrs :: Route a -> Set Text
- data RequestData
- waiReq :: RequestData -> Request
- nextApp :: RequestData -> Application
- runNext :: RequestData -> ResponseHandler
Quasi Quoters
parseRoutes :: QuasiQuoter Source
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
parseRoutesFile :: FilePath -> Q Exp Source
Parse routes declared in a file
parseRoutesNoCheck :: QuasiQuoter Source
Same as parseRoutes, but performs no overlap checking.
Parse routes declared inline, without checking for overlaps
parseRoutesFileNoCheck :: FilePath -> Q Exp Source
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 -> Middleware Source
Generates the application middleware from a Routable master datatype
URL rendering and parsing
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 -> ResponseHandler Source
A Handler generates an App from the master datatype
As of Wai 3, Application datatype now follows continuation passing style
type ResponseHandler = (Response -> IO ResponseReceived) -> IO ResponseReceived Source
Generated Datatypes
class Routable master where Source
A Routable instance can be used in dispatching.
An appropriate instance for your site datatype is
automatically generated by mkRoute
Methods
dispatcher :: Handler master Source
Used internally. However needs to be exported for TH to work.
class Eq (Route a) => RenderRoute a where Source
A RenderRoute instance for your site datatype is automatically generated by mkRoute
class RenderRoute a => ParseRoute a where Source
A ParseRoute instance for your site datatype is automatically generated by mkRoute
class RenderRoute a => RouteAttrs a where Source
Methods
Arguments
| :: Route a | |
| -> Set Text | A set of attributes associated with the route. |
A RouteAttrs instance for your site datatype is automatically generated by mkRoute
Accessing Request Data
data RequestData Source
An abstract representation of the request data. You can get the wai request object by using waiReq
waiReq :: RequestData -> Request Source
Extract the wai Request object from RequestData
nextApp :: RequestData -> Application Source
Extract the next Application in the stack
runNext :: RequestData -> ResponseHandler Source
Run the next application in the stack
Run the next application in the stack