servant-0.2: A family of combinators for defining webservices APIs and serving them

Safe HaskellNone
LanguageHaskell2010

Servant.API.Put

Synopsis

Documentation

data Put a Source

Endpoint for PUT requests, usually used to update a ressource. The type a is the type of the response body that's returned.

Example:

-- PUT /books/:isbn
-- with a Book as request body, returning the updated Book
type MyApi = "books" :> Capture "isbn" Text :> ReqBody Book :> Put Book

Instances

ToJSON a => HasServer (Put a)

When implementing the handler for a Put endpoint, just like for Delete, Get and Post, 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 200 along the way.

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