mig-0.2.1.0: Build lightweight and composable servers
Safe HaskellSafe-Inferred
LanguageGHC2021

Mig.Core.Class.Response

Description

Generic response

Synopsis

Documentation

data Resp (media :: Type) a Source #

Response with info on the media-type encoded as type.

Constructors

Resp 

Fields

Instances

Instances details
Functor (Resp media) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

fmap :: (a -> b) -> Resp media a -> Resp media b #

(<$) :: a -> Resp media b -> Resp media a #

Show a => Show (Resp media a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

showsPrec :: Int -> Resp media a -> ShowS #

show :: Resp media a -> String #

showList :: [Resp media a] -> ShowS #

Eq a => Eq (Resp media a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

(==) :: Resp media a -> Resp media a -> Bool #

(/=) :: Resp media a -> Resp media a -> Bool #

ToRespBody ty a => IsResp (Resp ty a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Associated Types

type RespBody (Resp ty a) Source #

type RespError (Resp ty a) Source #

type RespMedia (Resp ty a) Source #

type RespBody (Resp ty a) Source # 
Instance details

Defined in Mig.Core.Class.Response

type RespBody (Resp ty a) = a
type RespError (Resp ty a) Source # 
Instance details

Defined in Mig.Core.Class.Response

type RespError (Resp ty a) = a
type RespMedia (Resp ty a) Source # 
Instance details

Defined in Mig.Core.Class.Response

type RespMedia (Resp ty a) = ty

newtype RespOr ty err a Source #

Response that can contain an error. The error is represented with left case of an Either-type.

Constructors

RespOr 

Fields

Instances

Instances details
Functor (RespOr ty err) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

fmap :: (a -> b) -> RespOr ty err a -> RespOr ty err b #

(<$) :: a -> RespOr ty err b -> RespOr ty err a #

(Show err, Show a) => Show (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

showsPrec :: Int -> RespOr ty err a -> ShowS #

show :: RespOr ty err a -> String #

showList :: [RespOr ty err a] -> ShowS #

(Eq err, Eq a) => Eq (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

(==) :: RespOr ty err a -> RespOr ty err a -> Bool #

(/=) :: RespOr ty err a -> RespOr ty err a -> Bool #

(ToRespBody ty err, ToRespBody ty a) => IsResp (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Associated Types

type RespBody (RespOr ty err a) Source #

type RespError (RespOr ty err a) Source #

type RespMedia (RespOr ty err a) Source #

Methods

ok :: RespBody (RespOr ty err a) -> RespOr ty err a Source #

bad :: Status -> RespError (RespOr ty err a) -> RespOr ty err a Source #

noContent :: Status -> RespOr ty err a Source #

addHeaders :: ResponseHeaders -> RespOr ty err a -> RespOr ty err a Source #

getHeaders :: RespOr ty err a -> ResponseHeaders Source #

setStatus :: Status -> RespOr ty err a -> RespOr ty err a Source #

getRespBody :: RespOr ty err a -> Maybe (RespBody (RespOr ty err a)) Source #

getRespError :: RespOr ty err a -> Maybe (RespError (RespOr ty err a)) Source #

getStatus :: RespOr ty err a -> Status Source #

setMedia :: MediaType -> RespOr ty err a -> RespOr ty err a Source #

getMedia :: MediaType Source #

toResponse :: RespOr ty err a -> Response Source #

type RespBody (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

type RespBody (RespOr ty err a) = a
type RespError (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

type RespError (RespOr ty err a) = err
type RespMedia (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

type RespMedia (RespOr ty err a) = ty

class IsResp a where Source #

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 value
  • RespOr err a - for routes that can also produce an error or value.
  • Response - low-level HTTP-response.

Associated Types

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

Methods

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

Instances details
IsResp Response Source # 
Instance details

Defined in Mig.Core.Class.Response

ToRespBody ty a => IsResp (Resp ty a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Associated Types

type RespBody (Resp ty a) Source #

type RespError (Resp ty a) Source #

type RespMedia (Resp ty a) Source #

(ToRespBody ty err, ToRespBody ty a) => IsResp (RespOr ty err a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Associated Types

type RespBody (RespOr ty err a) Source #

type RespError (RespOr ty err a) Source #

type RespMedia (RespOr ty err a) Source #

Methods

ok :: RespBody (RespOr ty err a) -> RespOr ty err a Source #

bad :: Status -> RespError (RespOr ty err a) -> RespOr ty err a Source #

noContent :: Status -> RespOr ty err a Source #

addHeaders :: ResponseHeaders -> RespOr ty err a -> RespOr ty err a Source #

getHeaders :: RespOr ty err a -> ResponseHeaders Source #

setStatus :: Status -> RespOr ty err a -> RespOr ty err a Source #

getRespBody :: RespOr ty err a -> Maybe (RespBody (RespOr ty err a)) Source #

getRespError :: RespOr ty err a -> Maybe (RespError (RespOr ty err a)) Source #

getStatus :: RespOr ty err a -> Status Source #

setMedia :: MediaType -> RespOr ty err a -> RespOr ty err a Source #

getMedia :: MediaType Source #

toResponse :: RespOr ty err a -> Response Source #

badReq :: IsResp a => RespError a -> a Source #

Bad request. The bad response with 400 status.

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

data SetCookie a Source #

Constructors

SetCookie 

Instances

Instances details
Show a => Show (SetCookie a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Eq a => Eq (SetCookie a) Source # 
Instance details

Defined in Mig.Core.Class.Response

Methods

(==) :: SetCookie a -> SetCookie a -> Bool #

(/=) :: SetCookie a -> SetCookie a -> Bool #

defCookie :: a -> SetCookie a Source #

Default cookie which sets only the cookie itself.

setCookie :: (ToForm cookie, IsResp resp) => SetCookie cookie -> resp -> resp Source #

Set cookie as http header from form url encoded value