Safe Haskell | None |
---|---|
Language | Haskell2010 |
WebGear.Core.Trait.Body
Contents
Description
Traits and middlewares to handle request and response body payloads.
The requestBody
middleware attempts to convert the body to a
Haskell value or invoke an error handler if that fails.
The respondA
middleware generates a response from an HTTP status
and a response body.
If you need finer control over setting the body, use setBody
or
setBodyWithoutContentType
. These arrows accept a witnessed
response and a body and sets the body in the response. You can
generate an input response object using functions from
WebGear.Core.Trait.Status module.
Synopsis
- newtype Body mimeType t = Body mimeType
- data UnknownContentBody = UnknownContentBody
- requestBody :: forall t mt h (m :: Type -> Type) (ts :: [Type]). (Handler h m, Get h (Body mt t)) => mt -> h (With Request ts, Text) Response -> Middleware h ts (Body mt t ': ts)
- respondA :: forall body mt h (m :: Type -> Type). (Handler h m, Sets h '[Status, Body mt body, RequiredResponseHeader "Content-Type" Text], MIMEType mt) => Status -> mt -> h body Response
- setBody :: forall body mt h (ts :: [Type]). (Sets h '[Body mt body, RequiredResponseHeader "Content-Type" Text], MIMEType mt) => mt -> h (With Response ts, body) (With Response (Body mt body ': (RequiredResponseHeader "Content-Type" Text ': ts)))
- setBodyWithoutContentType :: forall h (ts :: [Type]). Set h UnknownContentBody => h (With Response ts, ResponseBody) (With Response (UnknownContentBody ': ts))
Traits
newtype Body mimeType t Source #
Request or response body with MIME types mimeTypes
and type t
.
Constructors
Body mimeType |
Instances
type Absence (Body mt t) Source # | |
Defined in WebGear.Core.Trait.Body | |
type Attribute (Body mt t) Request Source # | |
Defined in WebGear.Core.Trait.Body | |
type Attribute (Body mt t) Response Source # | |
Defined in WebGear.Core.Trait.Body | |
type Prerequisite (Body mt t) ts Source # | |
Defined in WebGear.Core.Trait.Body |
data UnknownContentBody Source #
Type representing responses without a statically known MIME type
Constructors
UnknownContentBody |
Instances
type Attribute UnknownContentBody Response Source # | |
Defined in WebGear.Core.Trait.Body |
Middlewares
setBody :: forall body mt h (ts :: [Type]). (Sets h '[Body mt body, RequiredResponseHeader "Content-Type" Text], MIMEType mt) => mt -> h (With Response ts, body) (With Response (Body mt body ': (RequiredResponseHeader "Content-Type" Text ': ts))) Source #
Set the response body along with a media type.
The MIME type mt
is used to set the "Content-Type" header in the
response.
Usage:
let body :: SomeJSONType = ...
response' <- setBody JSON
-< (response, body)
setBodyWithoutContentType :: forall h (ts :: [Type]). Set h UnknownContentBody => h (With Response ts, ResponseBody) (With Response (UnknownContentBody ': ts)) Source #
Set the response body without specifying any media type.
Usage:
let body :: ResponseBody = ... response' <- setBodyWithoutContentType -< (response, body)