serv-wai-0.2.0.0: Dependently typed API servers with Serv

Safe HaskellNone
LanguageHaskell2010

Serv.Wai.Response

Contents

Description

Functions and types for creating a Serv response to match a Api. A value of Response (s, Respond headers body) is a response with status code s :: Status, response headers headers :: [(Network.HTTP.Kinder.Header.HeaderName, *)] and a body described by body :: Body *.

Synopsis

Responses

data Response x where Source

A value of type 'Response (status, Respond headers body) fully describes one response a Serv server might emit.

Constructors

ContentResponse :: [Header] -> FieldRec hs -> a -> Response `(s, Respond hs (HasBody ts a))` 
EmptyResponse :: [Header] -> FieldRec hs -> Response `(s, Respond hs Empty)` 

type SomeResponse rs = Corec Response rs Source

A value of type 'SomeResponse rs' is a value of Response (s, r) such that (s, r) is an element of rs.

Construction

emptyResponse :: sing s -> Response `(s, Respond `[]` Empty)` Source

The empty response at a given status code: no headers, no body.

withBody :: a -> Response `(s, Respond hs Empty)` -> Response `(s, Respond hs (HasBody ts a))` Source

Attach a body to an empty Response.

withoutBody :: Response `(s, Respond hs (HasBody ts a))` -> Response `(s, Respond hs Empty)` Source

Eliminate a body in a Response, returning it to Empty.

withHeader :: Sing name -> value -> Response `(s, Respond headers body)` -> Response `(s, Respond (`(name, value)` : headers) body)` Source

Adds a header to a Response

withHeaderQuiet :: HeaderEncode name value => Sing name -> value -> Response `(s, Respond headers body)` -> Response `(s, Respond headers body)` Source

Unlike addHeader, addHeaderQuiet allows you to add headers not explicitly specified in the api specification.

Finalization

When constructing a response in our server implementation we do not build specific responses but instead responses which may be one of many possible server result types (parameterized by status codes). To represent this we use the SomeResponse type and use respond to convert from a normal Response to SomeResponse.

respond :: ElemOf rs `(s, r)` => Response `(s, r)` -> SomeResponse rs Source

Forget the details of a specific response making it an approprate response at a given Endpoint