liveBook · Manning

ReqBody

As explained in Learn Haskell by Example

ReqBody is a Servant combinator that specifies the type and media representation expected in an HTTP request body.

ReqBody is a Servant combinator for declaring the request-body type and media representation an endpoint expects. For example, a POST endpoint can require JSON encoding of SomeType or TodoEntry. section 17.1.1

type Api = "send" :> ReqBody '[JSON] SomeType :> PostNoContent

Requires a JSON SomeType body at /send and returns an empty response; Servant automatically rejects nonconforming requests. section 17.1.1

"add" :> ReqBody '[JSON] TodoEntry :> PostCreated '[JSON] Int

Places ReqBody in a todo-list API, accepting a JSON TodoEntry for the add endpoint before returning a created integer result. section 17.1.1

How Learn Haskell by Example covers it

How deep it goes
Defines the combinator’s placement and behavior through endpoint examples, but does not explain its internal validation mechanism.
Examples
Uses /send with SomeType and a todo-list /add endpoint with TodoEntry.
What it assumes
Requires a Servant route definition, an endpoint request type, and a chosen media representation such as JSON.
What you can do after
Apply it via Servant to declare typed JSON request bodies for POST endpoints.
How it connects
Connects request bodies with Servant, JSON, POST, PostNoContent, and PostCreated endpoint types.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.