Safe Haskell | None |
---|
- module Servant.Response
- data UpdateResponse o = UpdateResponse {}
- data LookupResponse a
Response
class
module Servant.Response
Useful reusable types and instances
data UpdateResponse o Source
A generic response type for any effectul operation
on a Resource
, like adding, updating or deleting an item.
It simply holds a Bool
that indicates whether the operation
was successful or not, and if it wasn't, it'll embed a text
describing what went wrong and is meant to be tagged
(see the o
type parameter) with the operation it's associated to.
This lets us have different instances for the standard Add and Update operations for example, where the former should respond with HTTP status code 201 if the entry was created, whereas the latter should just use status code 200.
You can of course skip this one and use a more appropriate for your particular application.
Eq (UpdateResponse o) | |
Show (UpdateResponse o) | |
Generic (UpdateResponse o) | |
ToJSON (UpdateResponse o) | e.g: { "success" : false, "msg" : "couldn't add item: blabla"} |
data LookupResponse a Source
A generic response type for an operation performing some kind of (potentially failing) lookup of an item
This is useful when writing a web application, where you
want to send for example a JSON message saying the item wasn't found
along with status 404 when the item isn't found, but just send the item
if it could be found. This is (purposefully) isomorphic to Maybe
.
Eq a => Eq (LookupResponse a) | |
Show a => Show (LookupResponse a) | |
ToJSON a => ToJSON (LookupResponse a) | If you have some type convertible to JSON,
you can wrap it in { "message" : "Not found" } if not found. This makes sure you send valid JSON through the wires even when the target doesn't exist. |
ToJSON a => Response (LookupResponse a) (Maybe a) | Make |