Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
WebGear handlers
Synopsis
- class (ArrowChoice h, ArrowPlus h, ArrowError RouteMismatch h, Monad m) => Handler h m | h -> m where
- arrM :: (a -> m b) -> h a b
- consumeRoute :: h RoutePath a -> h () a
- setDescription :: Description -> h a a
- setSummary :: Summary -> h a a
- newtype RoutePath = RoutePath [Text]
- data RouteMismatch = RouteMismatch
- newtype Description = Description {}
- newtype Summary = Summary {
- getSummary :: Text
- type RequestHandler h ts = h (Request `With` ts) Response
- type Middleware h tsOut tsIn = RequestHandler h tsIn -> RequestHandler h tsOut
- routeMismatch :: ArrowError RouteMismatch h => h a b
- unwitnessA :: Handler h m => h (Response `With` ts) Response
- (>->) :: Arrow h => h (env, stack) a -> h (env, (a, stack)) b -> h (env, stack) b
- (<-<) :: Arrow h => h (env, (a, stack)) b -> h (env, stack) a -> h (env, stack) b
Documentation
class (ArrowChoice h, ArrowPlus h, ArrowError RouteMismatch h, Monad m) => Handler h m | h -> m where Source #
A handler is an arrow with a monadic context.
Handlers have the following capabilities:
- Lift a monadic action into a handler arrow.
- Implement
ArrowChoice
typeclass so that conditionals can be used in arrow code. - Implement
ArrowPlus
for routing requests to specific handlers. - Provide contextual documentation elements - description and summary
arrM :: (a -> m b) -> h a b Source #
Lift a monadic function to a handler arrow
consumeRoute :: h RoutePath a -> h () a Source #
Consume all remaining path components with an arrow
setDescription :: Description -> h a a Source #
Set a description of a part of an API
setSummary :: Summary -> h a a Source #
Set a summary of a part of an API
Parts of the request path used by the routing machinery
data RouteMismatch Source #
Indicates that a handler cannot process this route
Instances
newtype Description Source #
Description associated with part of an API
Instances
A summary associated with part of an API
type RequestHandler h ts = h (Request `With` ts) Response Source #
A handler arrow from a witnessed request to response.
type Middleware h tsOut tsIn = RequestHandler h tsIn -> RequestHandler h tsOut Source #
A middleware enhances a RequestHandler
and produces another handler.
routeMismatch :: ArrowError RouteMismatch h => h a b Source #
Indicates that the request does not match the current handler.
unwitnessA :: Handler h m => h (Response `With` ts) Response Source #
Lifts unwitness
into a handler arrow.
(>->) :: Arrow h => h (env, stack) a -> h (env, (a, stack)) b -> h (env, stack) b infixr 1 Source #
Thread a response through commands from left to right.
For example, an HTTP 200 response with a body and Content-Type header can be generated with:
(ok200 -< ()) >-> (resp -> setBody "text/plain" -< (resp, "Hello World")) >-> (resp -> unwitnessA -< resp)
(<-<) :: Arrow h => h (env, (a, stack)) b -> h (env, stack) a -> h (env, stack) b infixr 1 Source #
Thread a response through commands from right to left.
For example, an HTTP 200 response with a body and Content-Type header can be generated with:
(resp -> unwitnessA -< resp) (resp - setBody "text/plain" -< (resp, "Hello World")) <-< (ok200 -< ())