webgear-server-0.1.0: Composable, type-safe library to build HTTP API servers
Copyright(c) Raghu Kaippully 2020
LicenseMPL-2.0
Maintainerrkaippully@gmail.com
Safe HaskellNone
LanguageHaskell2010

WebGear.Middlewares.Body

Description

Middlewares related to HTTP body.

Synopsis

Documentation

jsonRequestBody :: forall t m req res a. (FromJSON t, MonadRouter m, MonadIO m) => RequestMiddleware m req (JSONRequestBody t ': req) res a Source #

A middleware to parse the request body as JSON and convert it to a value via a FromJSON instance.

Usage for a type t which has a FromJSON instance:

jsonRequestBody @t handler

jsonResponseBody :: (ToJSON t, Monad m) => Middleware m req req res '[] t ByteString Source #

A middleware that converts the response that has a ToJSON instance to a ByteString response.

This will also set the "Content-Type" header of the response to "application/json".

Usage for a type t which has a ToJSON instance:

jsonResponseBody @t handler