servant-0.2

Safe HaskellNone
LanguageHaskell2010

Servant.API.Post

Synopsis

Documentation

data Post a Source

Endpoint for POST requests. The type variable represents the type of the response body (not the request body, use RQBody for that).

Example:

           -- POST /books
           -- with a JSON encoded Book as the request body
           -- returning the just-created Book
type MyApi = "books" :> ReqBody Book :> Post Book

Instances

VLinkHelper * (Post x) 
ToJSON a => HasServer (Post a)

When implementing the handler for a Post endpoint, just like for Delete, Get and Put, the handler code runs in the EitherT (Int, String) IO monad, where the Int represents the status code and the String a message, returned in case of failure. You can quite handily use left to quickly fail if some conditions are not met.

If successfully returning a value, we just require that its type has a ToJSON instance and servant takes care of encoding it for you, yielding status code 201 along the way.

Typeable (* -> *) Post 
type Server (Post a) = EitherT (Int, String) IO a