servant-namedargs-0.1.1.0: Combinators for servant providing named parameters

Safe HaskellNone
LanguageHaskell2010

Servant.API.NamedArgs

Description

This module provides combinators to represent named arguments to endpoints. Note that only link generation instances are provided here: you will most likely want one or both of Servant.Client.NamedArgs and Servant.Server.NamedArgs

Synopsis

Documentation

data NamedCapture' (mods :: [*]) (sym :: Symbol) (a :: *) Source #

Isomorphism of Capture'

Instances
(ToHttpApiData v, HasLink sub, KnownSymbol name) => HasLink (NamedCapture' mods name v :> sub :: Type) Source #

Becomes a named required argument

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedCapture' mods name v :> sub) a :: Type #

Methods

toLink :: (Link -> a) -> Proxy (NamedCapture' mods name v :> sub) -> Link -> MkLink (NamedCapture' mods name v :> sub) a #

type MkLink (NamedCapture' mods name v :> sub :: Type) a Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedCapture' mods name v :> sub :: Type) a = (name :! v) -> MkLink sub a

type NamedCapture = NamedCapture' '[] Source #

Isomorphism of Capture

data NamedCaptureAll (sym :: Symbol) (a :: *) Source #

Isomorphism of CaptureAll

Instances
(ToHttpApiData v, HasLink sub, KnownSymbol name) => HasLink (NamedCaptureAll name v :> sub :: Type) Source #

Becomes a named optional argument, taking a list and defaulting to an empty list

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedCaptureAll name v :> sub) a :: Type #

Methods

toLink :: (Link -> a) -> Proxy (NamedCaptureAll name v :> sub) -> Link -> MkLink (NamedCaptureAll name v :> sub) a #

type MkLink (NamedCaptureAll name v :> sub :: Type) a Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedCaptureAll name v :> sub :: Type) a = (name :? [v]) -> MkLink sub a

data NamedParam (mods :: [*]) (sym :: Symbol) (a :: *) Source #

Isomorphism of QueryParam'

Instances
(KnownSymbol name, HasLink sub, ToHttpApiData v, SBoolI (FoldRequired mods)) => HasLink (NamedParam mods name v :> sub :: Type) Source #

Becomes either a required or optional named argument depending on whether it is set as Required or Optional (defaults to optional if neither is specified)

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedParam mods name v :> sub) a :: Type #

Methods

toLink :: (Link -> a) -> Proxy (NamedParam mods name v :> sub) -> Link -> MkLink (NamedParam mods name v :> sub) a #

type MkLink (NamedParam mods name v :> sub :: Type) a Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedParam mods name v :> sub :: Type) a = RequiredNamedArgument mods name v -> MkLink sub a

type RequiredNamedParam = NamedParam '[Required, Strict] Source #

Shorthand for a required param, isomorphic to QueryParam' '[Required, Strict] from Servant

type OptionalNamedParam = NamedParam '[Optional, Strict] Source #

Shorthand for an optional param, isomorphic to QueryParam' '[Optional, Strict] from Servant

data NamedParams (sym :: Symbol) (a :: *) Source #

Isomorphism of QueryParams

Instances
(KnownSymbol name, HasLink sub, ToHttpApiData v) => HasLink (NamedParams name v :> sub :: Type) Source #

Becomes a required named argument, taking a list

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedParams name v :> sub) a :: Type #

Methods

toLink :: (Link -> a) -> Proxy (NamedParams name v :> sub) -> Link -> MkLink (NamedParams name v :> sub) a #

type MkLink (NamedParams name v :> sub :: Type) a Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedParams name v :> sub :: Type) a = (name :! [v]) -> MkLink sub a

data NamedFlag (sym :: Symbol) Source #

Isomorphism of QueryFlag

Instances
(KnownSymbol name, HasLink sub) => HasLink (NamedFlag name :> sub :: Type) Source #

Becomes an optional named argument, defaulting to False

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedFlag name :> sub) a :: Type #

Methods

toLink :: (Link -> a) -> Proxy (NamedFlag name :> sub) -> Link -> MkLink (NamedFlag name :> sub) a #

type MkLink (NamedFlag name :> sub :: Type) a Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedFlag name :> sub :: Type) a = (name :? Bool) -> MkLink sub a

data NamedHeader' (mods :: [*]) (sym :: Symbol) (a :: *) Source #

Isomorphism of Header'

Instances
HasLink sub => HasLink (NamedHeader' mods name a :> sub :: Type) Source #

Has no effect on the resulting link

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedHeader' mods name a :> sub) a :: Type #

Methods

toLink :: (Link -> a0) -> Proxy (NamedHeader' mods name a :> sub) -> Link -> MkLink (NamedHeader' mods name a :> sub) a0 #

type MkLink (NamedHeader' mods name a :> sub :: Type) r Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedHeader' mods name a :> sub :: Type) r = MkLink sub r

type NamedHeader = NamedHeader' '[Optional, Strict] Source #

Shorthand for a required Header; Isomorphism of Header

data NamedBody' (mods :: [*]) (sym :: Symbol) (contentTypes :: [*]) (a :: *) Source #

Named equivalent but not isomorphism of ReqBody'. ReqBody' doesn't have an associated name, so if you convert from a NamedBody' to a ReqBody' you will lose the associated name. Converting from a ReqBody' to a NamedBody' requires a default name be passed in. Like ReqBody', NamedBody' is always Required.

Instances
HasLink sub => HasLink (NamedBody' mods name ct a :> sub :: Type) Source #

Has no effect on the resulting link

Instance details

Defined in Servant.API.NamedArgs

Associated Types

type MkLink (NamedBody' mods name ct a :> sub) a :: Type #

Methods

toLink :: (Link -> a0) -> Proxy (NamedBody' mods name ct a :> sub) -> Link -> MkLink (NamedBody' mods name ct a :> sub) a0 #

type MkLink (NamedBody' mods name ct a :> sub :: Type) r Source # 
Instance details

Defined in Servant.API.NamedArgs

type MkLink (NamedBody' mods name ct a :> sub :: Type) r = MkLink sub r

type RequiredNamedArgument mods name a = If (FoldRequired mods) (name :! a) (name :? a) Source #

Returns the type name :! a if given a list including Required and name :? a otherwise

type RequestNamedArgument mods name a = If (FoldRequired mods) (name :! If (FoldLenient mods) (Either Text a) a) (name :? If (FoldLenient mods) (Either Text a) a) Source #

Returns either a NamedF Identity or NamedF Maybe depending on if required/optional, wrapping an Either Text a or an a depending on if lenient/strict

foldRequiredNamedArgument Source #

Arguments

:: (SBoolI (FoldRequired mods), KnownSymbol name) 
=> (a -> r)

Function to apply if the mods includes Required

-> (Maybe a -> r)

Function to apply if the mods do not include Required

-> RequiredNamedArgument mods name a

Argument to either f or g

-> r 

Apply either the function f which operates on a or g which operates on Maybe a depending on if the mods include Required

foldRequiredAdapter Source #

Arguments

:: (SBoolI (FoldRequired mods), KnownSymbol name) 
=> (If (FoldRequired mods) a (Maybe a) -> r)

Version of functions without named arguments

-> RequiredNamedArgument mods name a

Argument to either f or g

-> r 

Adapt a function supposed to take a or Maybe a to take name :! a or name :? a instead

unfoldRequestNamedArgument Source #

Arguments

:: (Monad m, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) 
=> m (RequestNamedArgument mods name a)

error when argument is required

-> (Text -> m (RequestNamedArgument mods name a))

error when argument is strictly parsed

-> Maybe (Either Text a)

value

-> m (RequestNamedArgument mods name a) 

Unfold a value into a RequestNamedArgument.

type family Transform (t :: [Transformation]) (api :: k) :: k where ... Source #

Transform is used to transform back and forth between APIs using the Named combinators and APIs not using the Named combinators by applying the listed transformations to the api

Equations

Transform t (a :<|> b) = Transform t a :<|> Transform t b 
Transform t (a :> b) = Transform t a :> Transform t b 
Transform (NameParams ': _) (QueryParam' mods sym a) = NamedParam mods sym a 
Transform (NameMultiParams ': _) (QueryParams sym a) = NamedParams sym a 
Transform (NameFlags ': _) (QueryFlag sym) = NamedFlag sym 
Transform (NameCaptures ': _) (Capture' mods sym a) = NamedCapture' mods sym a 
Transform (NameCaptureAlls ': _) (CaptureAll sym a) = NamedCaptureAll sym a 
Transform (NameHeaders ': _) (Header' mods sym a) = NamedHeader' mods sym a 
Transform (NameBodies name ': _) (ReqBody' mods ct a) = NamedBody' mods name ct a 
Transform (UnnameParams ': _) (NamedParam mods sym a) = QueryParam' mods sym a 
Transform (UnnameMultiParams ': _) (NamedParams sym a) = QueryParams sym a 
Transform (UnnameFlags ': _) (NamedFlag sym) = QueryFlag sym 
Transform (UnnameCaptures ': _) (NamedCapture' mods sym a) = Capture' mods sym a 
Transform (UnnameCaptureAlls ': _) (NamedCaptureAll sym a) = CaptureAll sym a 
Transform (UnnameHeaders ': _) (NamedHeader' mods sym a) = Header' mods sym a 
Transform (UnnameBodies ': _) (NamedBody' mods sym ct a) = ReqBody' mods ct a 
Transform (_ ': ts) a = Transform ts a 
Transform '[] a = a 

data AsTransformed (t :: [Transformation]) (m :: *) Source #

AsTransformed can be used to transform back and forth while using Servant's generic programming (see Servant.API.Generic)

Instances
GenericMode mode => GenericMode (AsTransformed t mode) Source # 
Instance details

Defined in Servant.API.NamedArgs

Associated Types

type (AsTransformed t mode) :- api :: Type #

type (AsTransformed t mode) :- api Source # 
Instance details

Defined in Servant.API.NamedArgs

type (AsTransformed t mode) :- api = mode :- Transform t api

data Transformation Source #

Possible transformations Transform can apply