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

Copyright(c) Anupam Jain 2013
LicenseMIT (see the file LICENSE)
Maintainerajnsit@gmail.com
Stabilityexperimental
Portabilitynon-portable (uses ghc extensions)
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Middleware.Routes.Handler

Description

Provides a HandlerM Monad that makes it easy to build Handlers

Synopsis

Documentation

type HandlerM sub master a = HandlerMI sub master IO a Source

The HandlerM Monad

A Monad that makes it easier to build a Handler

type HandlerMM master a = HandlerM master master a Source

A HandlerMM is a HandlerM Monad for use with a top level site (where the sub and master datatypes are the same)

HandlerM Monad specialised for top level sites (no subsites)

runHandlerM :: HandlerM sub master () -> HandlerS sub master Source

Run HandlerM, resulting in a Handler

Run a HandlerM to get a Handler

request :: HandlerM sub master Request Source

Get the request

Access the request data

reqHeader :: ByteString -> HandlerM sub master (Maybe ByteString) Source

Get a particular request header (Case insensitive)

Get a particular request header (case insensitive)

reqHeaders :: HandlerM sub master RequestHeaders Source

Get all request headers (Case insensitive)

Get all request headers (case insensitive)

routeAttrSet :: RouteAttrs sub => HandlerM sub master (Set Text) Source

Get the current route attributes

Access the route attribute list

rootRouteAttrSet :: RouteAttrs master => HandlerM sub master (Set Text) Source

Get the attributes for the current root route

Access the route attribute list for the root route

maybeRoute :: HandlerM sub master (Maybe (Route sub)) Source

Get the current route

Access the route data

maybeRootRoute :: HandlerM sub master (Maybe (Route master)) Source

Get the current root route

Access the root route data

showRouteMaster :: RenderRoute master => HandlerM sub master (Route master -> Text) Source

Get the route rendering function for the master site

Get the route rendering function for the master site

showRouteSub :: RenderRoute master => HandlerM sub master (Route sub -> Text) Source

Get the route rendering function for the subsite

Get the route rendering function for the subsite

showRouteQueryMaster :: RenderRoute master => HandlerM sub master (Route master -> [(Text, Text)] -> Text) Source

Get the route rendering function for the master site

Get the route + query params rendering function for the master site

showRouteQuerySub :: RenderRoute master => HandlerM sub master (Route sub -> [(Text, Text)] -> Text) Source

Get the route rendering function for the subsite

Get the route + query params rendering function for the subsite

readRouteMaster :: ParseRoute master => HandlerM sub master (Text -> Maybe (Route master)) Source

Get the route parsing function for the master site

Get the route parsing function for the master site

readRouteSub :: ParseRoute sub => HandlerM sub master (Text -> Maybe (Route master)) Source

Get the route parsing function for the subsite

Get the route parsing function for the subsite

master :: HandlerM sub master master Source

Get the master

Access the master datatype

sub :: HandlerM sub master sub Source

Get the sub

Access the sub datatype

rawBody :: HandlerM master master ByteString Source

Get the request body as a lazy bytestring. However consumes the entire body at once. TODO: Implement streaming. Prevent clash with direct use of requestBody

Consume and return the request body as a lazy bytestring

jsonBody :: FromJSON a => HandlerM master master (Either String a) Source

Parse the body as a JSON object

Consume and return the request body as JSON

header :: HeaderName -> ByteString -> HandlerM sub master () Source

Add a header to the application response TODO: Differentiate between setting and adding headers

Add a header to the response

status :: Status -> HandlerM sub master () Source

Set the response status

Set the response status

file :: FilePath -> HandlerM sub master () Source

Send a file as response

Send a file as response

filepart :: FilePath -> FilePart -> HandlerM sub master () Source

Send a part of a file as response

Send a part of a file as response

stream :: StreamingBody -> HandlerM sub master () Source

Stream the response

Stream a response

raw :: ByteString -> HandlerM sub master () Source

Set the response body

Set the raw response body

json :: ToJSON a => a -> HandlerM sub master () Source

Set the body of the response to the JSON encoding of the given value. Also sets "Content-Type" header to "application/json".

Set the json response body

plain :: Text -> HandlerM sub master () Source

Set the body of the response to the given Text value. Also sets "Content-Type" header to "text/plain".

Set the plain text response body

html :: Text -> HandlerM sub master () Source

Set the body of the response to the given Text value. Also sets "Content-Type" header to "text/html".

Set the html response body

css :: Text -> HandlerM sub master () Source

Set the body of the response to the given Text value. Also sets "Content-Type" header to "text/css".

Set the css response body

javascript :: Text -> HandlerM sub master () Source

Set the body of the response to the given Text value. Also sets "Content-Type" header to "text/javascript".

Set the javascript response body

asContent :: ByteString -> Text -> HandlerM sub master () Source

Sets the content-type header to the given Bytestring (look in Network.Wai.Middleware.Routes.ContentTypes for examples) And sets the body of the response to the given Text

Set the contentType and a Text body

next :: HandlerM sub master () Source

Run the next application

Run the next application in the stack

setCookie :: SetCookie -> HandlerM sub master () Source

Sets a cookie to the response

Add a cookie to the response

getCookie :: ByteString -> HandlerM sub master (Maybe ByteString) Source

Get a particular cookie

Get a cookie from the request

getCookies :: HandlerM sub master Cookies Source

Get all cookies

Get all cookies from the request