Stability | experimental |
---|---|
Maintainer | Alp Mestanogullari <alp@zalora.com> |
Safe Haskell | None |
Servant.Response
Description
This module contains a generic Response
class for tying the result
of some "database operation" to some response type of yours,
or to the standard ones from Servant.Scotty.Prelude for example.
- class ToJSON resp => Response resp result | result -> resp where
- toResponse :: result -> (resp, Status)
- module Network.HTTP.Types.Status
The Response
class
class ToJSON resp => Response resp result | result -> resp whereSource
A class that ties return types of your database operations and the output that will be generated to communicate the result.
- The first type,
resp
, is the response type that will be encoded in JSON and sent as the response body. - The second type,
result
, is the result type of your "database" or "context" operation.
For example, if you're adding an item, and if you're using
postgresql-simple, you'll probably want to use the
Response
instances defined in the servant-postgresql package,
in the Servant.PostgreSQL.Prelude
module.
It lets you specify, given a value of your result, if no exception is thrown, what response should be sent as JSON to the client along with what HTTP status.
There's a functional dependency at play: the result type of a database operation determines the representation that'll be picked for generating the json output.
Methods
toResponse :: result -> (resp, Status)Source
Instances
ToJSON a => Response [a] [a] | Just send the list of entries as a JSON array,
with status code 200. Used by |
ToJSON a => Response (LookupResponse a) (Maybe a) | Make |
Useful for defining your instances
module Network.HTTP.Types.Status