webgear-server-0.2.1: 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

data JSONRequestBody (t :: Type) Source #

A Trait for converting a JSON request body into a value.

Instances

Instances details
(FromJSON t, MonadIO m) => Trait (JSONRequestBody t :: Type) Request m Source # 
Instance details

Defined in WebGear.Middlewares.Body

type Attribute (JSONRequestBody t :: Type) Request Source # 
Instance details

Defined in WebGear.Middlewares.Body

type Absence (JSONRequestBody t :: Type) Request Source # 
Instance details

Defined in WebGear.Middlewares.Body

jsonRequestBody :: forall t m req a. (FromJSON t, MonadRouter m, MonadIO m) => RequestMiddleware' m req (JSONRequestBody t ': req) 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

Returns a 400 Bad Request response on failure to parse body.

jsonResponseBody :: (ToJSON t, Monad m) => ResponseMiddleware' m req 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