Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Generic response
Synopsis
- data Resp (media :: Type) a = Resp {}
- newtype RespOr ty err a = RespOr {}
- class IsResp a where
- type RespBody a :: Type
- type RespError a :: Type
- type RespMedia a :: Type
- ok :: RespBody a -> a
- bad :: Status -> RespError a -> a
- noContent :: Status -> a
- addHeaders :: ResponseHeaders -> a -> a
- getHeaders :: a -> ResponseHeaders
- setStatus :: Status -> a -> a
- getRespBody :: a -> Maybe (RespBody a)
- getRespError :: a -> Maybe (RespError a)
- getStatus :: a -> Status
- setMedia :: MediaType -> a -> a
- getMedia :: MediaType
- toResponse :: a -> Response
- badReq :: IsResp a => RespError a -> a
- internalServerError :: IsResp a => RespError a -> a
- notImplemented :: IsResp a => RespError a -> a
- redirect :: IsResp a => Text -> a
- setHeader :: (IsResp a, ToHttpApiData h) => HeaderName -> h -> a -> a
- data SetCookie a = SetCookie {}
- defCookie :: a -> SetCookie a
- setCookie :: (ToForm cookie, IsResp resp) => SetCookie cookie -> resp -> resp
Documentation
data Resp (media :: Type) a Source #
Response with info on the media-type encoded as type.
Instances
newtype RespOr ty err a Source #
Response that can contain an error. The error is represented with left case of an Either
-type.
Instances
Values that can be converted to low-level response.
The repsonse value is usually one of two cases:
Resp a
-- for routes which always produce a valueRespOr err a
- for routes that can also produce an error or value.Response
- low-level HTTP-response.
ok, bad, noContent, addHeaders, getHeaders, setStatus, getRespBody, getRespError, getStatus, getMedia, toResponse
type RespBody a :: Type Source #
the type of response body value
type RespError a :: Type Source #
the type of an error
type RespMedia a :: Type Source #
the media tpye of resp
ok :: RespBody a -> a Source #
Returns valid repsonse with 200 status
bad :: Status -> RespError a -> a Source #
Returns an error with given status
noContent :: Status -> a Source #
response with no content
addHeaders :: ResponseHeaders -> a -> a Source #
Add some header to the response
getHeaders :: a -> ResponseHeaders Source #
Get response headers
setStatus :: Status -> a -> a Source #
Sets repsonse status
getRespBody :: a -> Maybe (RespBody a) Source #
Get response body
getRespError :: a -> Maybe (RespError a) Source #
Get response error
getStatus :: a -> Status Source #
Get response status
setMedia :: MediaType -> a -> a Source #
Set the media type of the response
getMedia :: MediaType Source #
Reads the media type by response type
toResponse :: a -> Response Source #
Converts value to low-level response
Instances
internalServerError :: IsResp a => RespError a -> a Source #
Internal server error. The bad
response with 500 status.
notImplemented :: IsResp a => RespError a -> a Source #
Not implemented route. The bad
response with 501 status.
redirect :: IsResp a => Text -> a Source #
Redirect to url. It is bad
response with 302 status and set header of Location to a given URL.
setHeader :: (IsResp a, ToHttpApiData h) => HeaderName -> h -> a -> a Source #
Set header for response