Safe Haskell | None |
---|---|
Language | Haskell2010 |
Generalizes all the data needed to make code generation work with arbitrary programming languages.
Synopsis
- data ArgType
- data HeaderArg f
- = HeaderArg {
- _headerArg :: Arg f
- | ReplaceHeaderArg {
- _headerArg :: Arg f
- _headerPattern :: Text
- = HeaderArg {
- data QueryArg f = QueryArg {
- _queryArgName :: Arg f
- _queryArgType :: ArgType
- data Req f = Req {
- _reqUrl :: Url f
- _reqMethod :: Method
- _reqHeaders :: [HeaderArg f]
- _reqBody :: Maybe f
- _reqReturnType :: Maybe f
- _reqFuncName :: FunctionName
- _reqBodyContentType :: ReqBodyContentType
- data ReqBodyContentType
- newtype Segment f = Segment {
- unSegment :: SegmentType f
- data SegmentType f
- = Static PathSegment
- | Cap (Arg f)
- data Url f = Url {}
- type Path f = [Segment f]
- data Arg f = Arg {
- _argName :: PathSegment
- _argType :: f
- newtype FunctionName = FunctionName {
- unFunctionName :: [Text]
- newtype PathSegment = PathSegment {}
- argName :: forall f. Lens' (Arg f) PathSegment
- argType :: forall f f. Lens (Arg f) (Arg f) f f
- argPath :: Getter (Arg f) Text
- reqUrl :: forall f. Lens' (Req f) (Url f)
- reqMethod :: forall f. Lens' (Req f) Method
- reqHeaders :: forall f. Lens' (Req f) [HeaderArg f]
- reqBody :: forall f. Lens' (Req f) (Maybe f)
- reqBodyContentType :: forall f. Lens' (Req f) ReqBodyContentType
- reqReturnType :: forall f. Lens' (Req f) (Maybe f)
- reqFuncName :: forall f. Lens' (Req f) FunctionName
- path :: forall f. Lens' (Url f) (Path f)
- queryStr :: forall f. Lens' (Url f) [QueryArg f]
- queryArgName :: forall f f. Lens (QueryArg f) (QueryArg f) (Arg f) (Arg f)
- queryArgType :: forall f. Lens' (QueryArg f) ArgType
- headerArg :: forall f f. Lens (HeaderArg f) (HeaderArg f) (Arg f) (Arg f)
- _PathSegment :: Iso' PathSegment Text
- _HeaderArg :: forall f. Prism' (HeaderArg f) (Arg f)
- _ReplaceHeaderArg :: forall f. Prism' (HeaderArg f) (Arg f, Text)
- _Static :: forall f. Prism' (SegmentType f) PathSegment
- _Cap :: forall f f. Prism (SegmentType f) (SegmentType f) (Arg f) (Arg f)
- _Normal :: Prism' ArgType ()
- _Flag :: Prism' ArgType ()
- _List :: Prism' ArgType ()
- class HasForeign lang ftype (api :: *) where
- class HasForeignType lang ftype a where
- class GenerateList ftype reqs where
- generateList :: reqs -> [Req ftype]
- data NoTypes
- captureArg :: Segment f -> Arg f
- isCapture :: Segment f -> Bool
- defReq :: Req ftype
- listFromAPI :: (HasForeign lang ftype api, GenerateList ftype (Foreign ftype api)) => Proxy lang -> Proxy ftype -> Proxy api -> [Req ftype]
- module Servant.API
- module Servant.Foreign.Inflections
Documentation
Instances
Eq ArgType Source # | |
Data ArgType Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ArgType -> c ArgType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ArgType # toConstr :: ArgType -> Constr # dataTypeOf :: ArgType -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ArgType) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgType) # gmapT :: (forall b. Data b => b -> b) -> ArgType -> ArgType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgType -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArgType -> r # gmapQ :: (forall d. Data d => d -> u) -> ArgType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ArgType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ArgType -> m ArgType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ArgType -> m ArgType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ArgType -> m ArgType # | |
Show ArgType Source # | |
HeaderArg | |
| |
ReplaceHeaderArg | |
|
Instances
Eq f => Eq (HeaderArg f) Source # | |
Data f => Data (HeaderArg f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> HeaderArg f -> c (HeaderArg f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (HeaderArg f) # toConstr :: HeaderArg f -> Constr # dataTypeOf :: HeaderArg f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (HeaderArg f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (HeaderArg f)) # gmapT :: (forall b. Data b => b -> b) -> HeaderArg f -> HeaderArg f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> HeaderArg f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> HeaderArg f -> r # gmapQ :: (forall d. Data d => d -> u) -> HeaderArg f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> HeaderArg f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> HeaderArg f -> m (HeaderArg f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> HeaderArg f -> m (HeaderArg f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> HeaderArg f -> m (HeaderArg f) # | |
Show f => Show (HeaderArg f) Source # | |
QueryArg | |
|
Instances
Eq f => Eq (QueryArg f) Source # | |
Data f => Data (QueryArg f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> QueryArg f -> c (QueryArg f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (QueryArg f) # toConstr :: QueryArg f -> Constr # dataTypeOf :: QueryArg f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (QueryArg f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (QueryArg f)) # gmapT :: (forall b. Data b => b -> b) -> QueryArg f -> QueryArg f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> QueryArg f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> QueryArg f -> r # gmapQ :: (forall d. Data d => d -> u) -> QueryArg f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> QueryArg f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> QueryArg f -> m (QueryArg f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> QueryArg f -> m (QueryArg f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> QueryArg f -> m (QueryArg f) # | |
Show f => Show (QueryArg f) Source # | |
Req | |
|
Instances
GenerateList ftype (Req ftype) Source # | |
Defined in Servant.Foreign.Internal generateList :: Req ftype -> [Req ftype] Source # | |
Eq f => Eq (Req f) Source # | |
Data f => Data (Req f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Req f -> c (Req f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Req f) # dataTypeOf :: Req f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Req f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Req f)) # gmapT :: (forall b. Data b => b -> b) -> Req f -> Req f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Req f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Req f -> r # gmapQ :: (forall d. Data d => d -> u) -> Req f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Req f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Req f -> m (Req f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Req f -> m (Req f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Req f -> m (Req f) # | |
Show f => Show (Req f) Source # | |
data ReqBodyContentType Source #
Instances
Segment | |
|
Instances
Eq f => Eq (Segment f) Source # | |
Data f => Data (Segment f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Segment f -> c (Segment f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Segment f) # toConstr :: Segment f -> Constr # dataTypeOf :: Segment f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Segment f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Segment f)) # gmapT :: (forall b. Data b => b -> b) -> Segment f -> Segment f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Segment f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Segment f -> r # gmapQ :: (forall d. Data d => d -> u) -> Segment f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Segment f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Segment f -> m (Segment f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Segment f -> m (Segment f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Segment f -> m (Segment f) # | |
Show f => Show (Segment f) Source # | |
data SegmentType f Source #
Static PathSegment | a static path segment. like "/foo" |
Cap (Arg f) | a capture. like "/:userid" |
Instances
Eq f => Eq (SegmentType f) Source # | |
Defined in Servant.Foreign.Internal (==) :: SegmentType f -> SegmentType f -> Bool # (/=) :: SegmentType f -> SegmentType f -> Bool # | |
Data f => Data (SegmentType f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SegmentType f -> c (SegmentType f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (SegmentType f) # toConstr :: SegmentType f -> Constr # dataTypeOf :: SegmentType f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (SegmentType f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (SegmentType f)) # gmapT :: (forall b. Data b => b -> b) -> SegmentType f -> SegmentType f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SegmentType f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SegmentType f -> r # gmapQ :: (forall d. Data d => d -> u) -> SegmentType f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SegmentType f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SegmentType f -> m (SegmentType f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SegmentType f -> m (SegmentType f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SegmentType f -> m (SegmentType f) # | |
Show f => Show (SegmentType f) Source # | |
Defined in Servant.Foreign.Internal showsPrec :: Int -> SegmentType f -> ShowS # show :: SegmentType f -> String # showList :: [SegmentType f] -> ShowS # |
Instances
Eq f => Eq (Url f) Source # | |
Data f => Data (Url f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Url f -> c (Url f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Url f) # dataTypeOf :: Url f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Url f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Url f)) # gmapT :: (forall b. Data b => b -> b) -> Url f -> Url f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Url f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Url f -> r # gmapQ :: (forall d. Data d => d -> u) -> Url f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Url f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Url f -> m (Url f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Url f -> m (Url f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Url f -> m (Url f) # | |
Show f => Show (Url f) Source # | |
Arg | |
|
Instances
Eq f => Eq (Arg f) Source # | |
Data f => Data (Arg f) Source # | |
Defined in Servant.Foreign.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Arg f -> c (Arg f) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Arg f) # dataTypeOf :: Arg f -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Arg f)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Arg f)) # gmapT :: (forall b. Data b => b -> b) -> Arg f -> Arg f # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Arg f -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Arg f -> r # gmapQ :: (forall d. Data d => d -> u) -> Arg f -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Arg f -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Arg f -> m (Arg f) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Arg f -> m (Arg f) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Arg f -> m (Arg f) # | |
Show f => Show (Arg f) Source # | |
newtype FunctionName Source #
Instances
newtype PathSegment Source #
Instances
reqBodyContentType :: forall f. Lens' (Req f) ReqBodyContentType Source #
reqFuncName :: forall f. Lens' (Req f) FunctionName Source #
_Static :: forall f. Prism' (SegmentType f) PathSegment Source #
_Cap :: forall f f. Prism (SegmentType f) (SegmentType f) (Arg f) (Arg f) Source #
class HasForeign lang ftype (api :: *) where Source #
Instances
HasForeign (lang :: k) ftype Raw Source # | |
HasForeign (lang :: k) ftype EmptyAPI Source # | |
(HasForeign lang ftype a, HasForeign lang ftype b) => HasForeign (lang :: k) ftype (a :<|> b) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (Description desc :> api) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (Description desc :> api) -> Req ftype -> Foreign ftype (Description desc :> api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (Summary desc :> api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (HttpVersion :> api) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (HttpVersion :> api) -> Req ftype -> Foreign ftype (HttpVersion :> api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (WithNamedContext name context api) Source # | |
Defined in Servant.Foreign.Internal type Foreign ftype (WithNamedContext name context api) :: Type Source # foreignFor :: Proxy lang -> Proxy ftype -> Proxy (WithNamedContext name context api) -> Req ftype -> Foreign ftype (WithNamedContext name context api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (Vault :> api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (IsSecure :> api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (RemoteHost :> api) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (RemoteHost :> api) -> Req ftype -> Foreign ftype (RemoteHost :> api) Source # | |
(KnownSymbol path, HasForeign lang ftype api) => HasForeign (lang :: k) ftype (path :> api) Source # | |
HasForeign lang ftype api => HasForeign (lang :: k) ftype (StreamBody' mods framing ctype a :> api) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (StreamBody' mods framing ctype a :> api) -> Req ftype -> Foreign ftype (StreamBody' mods framing ctype a :> api) Source # | |
(Elem JSON list, HasForeignType lang ftype a, HasForeign lang ftype api) => HasForeign (lang :: k) ftype (ReqBody' mods list a :> api) Source # | |
(KnownSymbol sym, HasForeignType lang ftype Bool, HasForeign lang ftype api) => HasForeign (lang :: k) ftype (QueryFlag sym :> api) Source # | |
(KnownSymbol sym, HasForeignType lang ftype [a], HasForeign lang ftype api) => HasForeign (lang :: k) ftype (QueryParams sym a :> api) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (QueryParams sym a :> api) -> Req ftype -> Foreign ftype (QueryParams sym a :> api) Source # | |
(KnownSymbol sym, HasForeignType lang ftype (RequiredArgument mods a), HasForeign lang ftype api) => HasForeign (lang :: k) ftype (QueryParam' mods sym a :> api) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (QueryParam' mods sym a :> api) -> Req ftype -> Foreign ftype (QueryParam' mods sym a :> api) Source # | |
(KnownSymbol sym, HasForeignType lang ftype (RequiredArgument mods a), HasForeign lang ftype api) => HasForeign (lang :: k) ftype (Header' mods sym a :> api) Source # | |
(KnownSymbol sym, HasForeignType lang ftype [t], HasForeign lang ftype sublayout) => HasForeign (lang :: k) ftype (CaptureAll sym t :> sublayout) Source # | |
Defined in Servant.Foreign.Internal foreignFor :: Proxy lang -> Proxy ftype -> Proxy (CaptureAll sym t :> sublayout) -> Req ftype -> Foreign ftype (CaptureAll sym t :> sublayout) Source # | |
(KnownSymbol sym, HasForeignType lang ftype t, HasForeign lang ftype api) => HasForeign (lang :: k) ftype (Capture' mods sym t :> api) Source # | |
(Elem JSON list, HasForeignType lang ftype a, ReflectMethod method) => HasForeign (lang :: k) ftype (Verb method status list a) Source # | |
(ct ~ JSON, HasForeignType lang ftype a, ReflectMethod method) => HasForeign (lang :: k) ftype (Stream method status framing ct a) Source # | TODO: doesn't taking framing into account. |
class HasForeignType lang ftype a where Source #
HasForeignType
maps Haskell types with types in the target
language of your backend. For example, let's say you're
implementing a backend to some language X, and you want
a Text representation of each input/output type mentioned in the API:
-- First you need to create a dummy type to parametrize your -- instances. data LangX -- Otherwise you define instances for the types you need instance HasForeignType LangX Text Int where typeFor _ _ _ = "intX" -- Or for example in case of lists instance HasForeignType LangX Text a => HasForeignType LangX Text [a] where typeFor lang type _ = "listX of " <> typeFor lang ftype (Proxy :: Proxy a)
Finally to generate list of information about all the endpoints for an API you create a function of a form:
getEndpoints :: (HasForeign LangX Text api, GenerateList Text (Foreign Text api)) => Proxy api -> [Req Text] getEndpoints api = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy Text) api
-- If language __X__ is dynamically typed then you can use -- a predefined NoTypes parameter with the NoContent output type:
getEndpoints :: (HasForeign NoTypes NoContent api, GenerateList Text (Foreign NoContent api)) => Proxy api -> [Req NoContent] getEndpoints api = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) api
class GenerateList ftype reqs where Source #
Utility class used by listFromAPI
which computes
the data needed to generate a function for each endpoint
and hands it all back in a list.
generateList :: reqs -> [Req ftype] Source #
Instances
GenerateList ftype EmptyForeignAPI Source # | |
Defined in Servant.Foreign.Internal generateList :: EmptyForeignAPI -> [Req ftype] Source # | |
GenerateList ftype (Req ftype) Source # | |
Defined in Servant.Foreign.Internal generateList :: Req ftype -> [Req ftype] Source # | |
(GenerateList ftype start, GenerateList ftype rest) => GenerateList ftype (start :<|> rest) Source # | |
Defined in Servant.Foreign.Internal generateList :: (start :<|> rest) -> [Req ftype] Source # |
captureArg :: Segment f -> Arg f Source #
listFromAPI :: (HasForeign lang ftype api, GenerateList ftype (Foreign ftype api)) => Proxy lang -> Proxy ftype -> Proxy api -> [Req ftype] Source #
Generate the necessary data for codegen as a list, each Req
describing one endpoint from your API type.
module Servant.API
module Servant.Foreign.Inflections