Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Response x where
- type SomeResponse rs = Corec Response rs
- emptyResponse :: sing s -> Response `(s, Respond `[]` Empty)`
- withBody :: a -> Response `(s, Respond hs Empty)` -> Response `(s, Respond hs (HasBody ts a))`
- withoutBody :: Response `(s, Respond hs (HasBody ts a))` -> Response `(s, Respond hs Empty)`
- withHeader :: Sing name -> value -> Response `(s, Respond headers body)` -> Response `(s, Respond (`(name, value)` : headers) body)`
- withHeaderQuiet :: HeaderEncode name value => Sing name -> value -> Response `(s, Respond headers body)` -> Response `(s, Respond headers body)`
- respond :: ElemOf rs `(s, r)` => Response `(s, r)` -> SomeResponse rs
Responses
A value of type 'Response (status,
fully describes one response a Serv server might emit.Respond
headers body)
type SomeResponse rs = Corec Response rs Source
A value of type 'SomeResponse rs'
is a value of
such that Response
(s, r)(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
.
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
.