Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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 :: Type) (t :: Type) = Body mimeType
- data UnknownContentBody = UnknownContentBody
- requestBody :: forall t mt h m ts. (Handler h m, Get h (Body mt t) Request) => mt -> h (Request `With` ts, Text) Response -> Middleware h ts (Body mt t : ts)
- respondA :: forall body mt h m. (Handler h m, Sets h [Status, Body mt body, RequiredResponseHeader "Content-Type" Text] Response, MIMEType mt) => Status -> mt -> h body Response
- setBody :: forall body mt h ts. (Sets h [Body mt body, RequiredResponseHeader "Content-Type" Text] Response, MIMEType mt) => mt -> h (Response `With` ts, body) (Response `With` (Body mt body : (RequiredResponseHeader "Content-Type" Text : ts)))
- setBodyWithoutContentType :: forall h ts. Set h UnknownContentBody Response => h (Response `With` ts, ResponseBody) (Response `With` (UnknownContentBody : ts))
Traits
newtype Body (mimeType :: Type) (t :: Type) Source #
Request or response body with MIME types mimeTypes
and type t
.
Body mimeType |
Instances
Trait (Body mt t) Request Source # | |
Trait (Body mt t) Response Source # | |
TraitAbsence (Body mt t) Request Source # | |
type Absence (Body mt t) Request 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 Request Source # | |
Defined in WebGear.Core.Trait.Body |
data UnknownContentBody Source #
Type representing responses without a statically known MIME type
Instances
Trait UnknownContentBody Response Source # | |
Defined in WebGear.Core.Trait.Body | |
type Attribute UnknownContentBody Response Source # | |
Defined in WebGear.Core.Trait.Body |
Middlewares
setBody :: forall body mt h ts. (Sets h [Body mt body, RequiredResponseHeader "Content-Type" Text] Response, MIMEType mt) => mt -> h (Response `With` ts, body) (Response `With` (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. Set h UnknownContentBody Response => h (Response `With` ts, ResponseBody) (Response `With` (UnknownContentBody : ts)) Source #
Set the response body without specifying any media type.
Usage:
let body :: ResponseBody = ... response' <- setBodyWithoutContentType -< (response, body)