servant-0.16.2: A family of combinators for defining webservices APIs

Safe HaskellNone
LanguageHaskell2010

Servant.API.Modifiers

Contents

Synopsis

Required / optional argument

data Required Source #

Required argument. Not wrapped.

data Optional Source #

Optional argument. Wrapped in Maybe.

Instances
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a

HasResponseHeader h a (Header h a ': rest) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

hlistLookupHeader :: HList (Header h a ': rest) -> ResponseHeader h a

(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders' :: Headers (Header h v ': rest) a -> [Header0]

(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

buildHeadersTo :: [Header0] -> HList (Header h v ': xs) Source #

type FoldRequired mods = FoldRequired' False mods Source #

Fold modifier list to decide whether argument is required.

>>> :kind! FoldRequired '[Required, Description "something"]
FoldRequired '[Required, Description "something"] :: Bool
= 'True
>>> :kind! FoldRequired '[Required, Optional]
FoldRequired '[Required, Optional] :: Bool
= 'False
>>> :kind! FoldRequired '[]
FoldRequired '[] :: Bool
= 'False

type family FoldRequired' (acc :: Bool) (mods :: [*]) :: Bool where ... Source #

Implementation of FoldRequired.

Equations

FoldRequired' acc '[] = acc 
FoldRequired' acc (Required ': mods) = FoldRequired' True mods 
FoldRequired' acc (Optional ': mods) = FoldRequired' False mods 
FoldRequired' acc (mod ': mods) = FoldRequired' acc mods 

Lenient / strict parsing

data Lenient Source #

Leniently parsed argument, i.e. parsing never fail. Wrapped in Either Text.

data Strict Source #

Strictly parsed argument. Not wrapped.

Instances
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a

HasResponseHeader h a (Header h a ': rest) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

hlistLookupHeader :: HList (Header h a ': rest) -> ResponseHeader h a

(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders' :: Headers (Header h v ': rest) a -> [Header0]

(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) Source # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

buildHeadersTo :: [Header0] -> HList (Header h v ': xs) Source #

type FoldLenient mods = FoldLenient' False mods Source #

Fold modifier list to decide whether argument should be parsed strictly or leniently.

>>> :kind! FoldLenient '[]
FoldLenient '[] :: Bool
= 'False

type family FoldLenient' (acc :: Bool) (mods :: [*]) :: Bool where ... Source #

Implementation of FoldLenient.

Equations

FoldLenient' acc '[] = acc 
FoldLenient' acc (Lenient ': mods) = FoldLenient' True mods 
FoldLenient' acc (Strict ': mods) = FoldLenient' False mods 
FoldLenient' acc (mod ': mods) = FoldLenient' acc mods 

Utilities

type RequiredArgument mods a = If (FoldRequired mods) a (Maybe a) Source #

Helper type alias.

foldRequiredArgument Source #

Arguments

:: SBoolI (FoldRequired mods) 
=> Proxy mods 
-> (a -> r)

Required

-> (Maybe a -> r)

Optional

-> RequiredArgument mods a 
-> r 

Fold a RequiredAgument into a value

unfoldRequiredArgument Source #

Arguments

:: (Monad m, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) 
=> Proxy mods 
-> m (RequiredArgument mods a)

error when argument is required

-> (Text -> m (RequiredArgument mods a))

error when argument is strictly parsed

-> Maybe (Either Text a)

value

-> m (RequiredArgument mods a) 

Unfold a value into a RequiredArgument.

type RequestArgument mods a = If (FoldRequired mods) (If (FoldLenient mods) (Either Text a) a) (Maybe (If (FoldLenient mods) (Either Text a) a)) Source #

Helper type alias.

By default argument is Optional and Strict.

unfoldRequestArgument Source #

Arguments

:: (Monad m, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) 
=> Proxy mods 
-> m (RequestArgument mods a)

error when argument is required

-> (Text -> m (RequestArgument mods a))

error when argument is strictly parsed

-> Maybe (Either Text a)

value

-> m (RequestArgument mods a) 

Unfold a value into a RequestArgument.