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

Safe Haskell | None
Language | Haskell2010

Servant.API.Modifiers

Contents

- Required / optional argument
- Lenient / strict parsing
- Utilities

Synopsis

- data Required
- data Optional
- type FoldRequired mods = FoldRequired' 'False mods
- type family FoldRequired' (acc :: Bool) (mods :: [*]) :: Bool where ...
- data Lenient
- data Strict
- type FoldLenient mods = FoldLenient' 'False mods
- type family FoldLenient' (acc :: Bool) (mods :: [*]) :: Bool where ...
- type RequiredArgument mods a = If (FoldRequired mods) a (Maybe a)
- foldRequiredArgument :: forall mods a r. SBoolI (FoldRequired mods) => Proxy mods -> (a -> r) -> (Maybe a -> r) -> RequiredArgument mods a -> r
- unfoldRequiredArgument :: forall mods m a. (Monad m, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => Proxy mods -> m (RequiredArgument mods a) -> (Text -> m (RequiredArgument mods a)) -> Maybe (Either Text a) -> m (RequiredArgument mods a)
- type RequestArgument mods a = If (FoldRequired mods) (If (FoldLenient mods) (Either Text a) a) (Maybe (If (FoldLenient mods) (Either Text a) a))
- unfoldRequestArgument :: forall mods m a. (Monad m, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => Proxy mods -> m (RequestArgument mods a) -> (Text -> m (RequestArgument mods a)) -> Maybe (Either Text a) -> m (RequestArgument mods a)

# Required / optional argument

data Required Source #

Required argument. Not wrapped.

data Optional Source #

Optional argument. Wrapped in `Maybe`.

#### Instances

Instances details

(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

Instances details

(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.

- `Required` ↦ `a`
- `Optional` ↦ ``Maybe` a`

foldRequiredArgument Source #

Arguments

:: forall mods a r. 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

:: forall mods m a. (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`.

- `Required`, `Strict` ↦ `a`
- `Required`, `Lenient` ↦ ``Either` `Text` a`
- `Optional`, `Strict` ↦ ``Maybe` a`
- `Optional`, `Lenient` ↦ ``Maybe` (`Either` `Text` a)`

unfoldRequestArgument Source #

Arguments

:: forall mods m a. (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`.