webgear-core-1.3.1: Composable, type-safe library to build HTTP APIs
Safe HaskellSafe-Inferred
LanguageHaskell2010

WebGear.Core.Handler

Description

WebGear handlers

Synopsis

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

Methods

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

newtype RoutePath Source #

Parts of the request path used by the routing machinery

Constructors

RoutePath [Text] 

Instances

Instances details
IsList RoutePath Source # 
Instance details

Defined in WebGear.Core.Handler

Associated Types

type Item RoutePath #

Show RoutePath Source # 
Instance details

Defined in WebGear.Core.Handler

Eq RoutePath Source # 
Instance details

Defined in WebGear.Core.Handler

type Item RoutePath Source # 
Instance details

Defined in WebGear.Core.Handler

newtype Summary Source #

A summary associated with part of an API

Constructors

Summary 

Fields

Instances

Instances details
IsString Summary Source # 
Instance details

Defined in WebGear.Core.Handler

Methods

fromString :: String -> Summary #

Read Summary Source # 
Instance details

Defined in WebGear.Core.Handler

Show Summary Source # 
Instance details

Defined in WebGear.Core.Handler

Eq Summary Source # 
Instance details

Defined in WebGear.Core.Handler

Methods

(==) :: Summary -> Summary -> Bool #

(/=) :: Summary -> Summary -> Bool #

Ord Summary Source # 
Instance details

Defined in WebGear.Core.Handler

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 -< ())