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

Safe HaskellNone
LanguageHaskell2010

Servant.API.ReqBody

Synopsis

Documentation

data ReqBody a Source

Extract the request body as a value of type a.

Example:

           -- POST /books
type MyApi = "books" :> ReqBody Book :> Post Book

Instances

(FromJSON a, HasServer sublayout) => HasServer ((:>) * (ReqBody * a) sublayout)

If you use ReqBody in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of the type specified by ReqBody. This lets servant worry about extracting it from the request and turning it into a value of the type you specify.

All it asks is for a FromJSON instance.

Example:

type MyApi = "books" :> ReqBody Book :> Post Book

server :: Server MyApi
server = postBook
  where postBook :: Book -> EitherT (Int, String) IO Book
        postBook book = ...insert into your db...
type Server ((:>) * (ReqBody * a) sublayout) = a -> Server sublayout