Safe Haskell | None |
---|---|
Language | Haskell2010 |
Generalizes all the data needed to make code generation work with arbitrary programming languages.
- 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
- 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)
- 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
- 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
HeaderArg | |
| |
ReplaceHeaderArg | |
|
QueryArg | |
|
Req | |
|
Segment | |
|
data SegmentType f Source #
Static PathSegment | a static path segment. like "/foo" |
Cap (Arg f) | a capture. like "/:userid" |
Eq f => Eq (SegmentType f) Source # | |
Data f => Data (SegmentType f) Source # | |
Show f => Show (SegmentType f) Source # | |
Arg | |
|
newtype FunctionName Source #
newtype PathSegment 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 #
HasForeign k lang ftype Raw Source # | |
HasForeign k lang ftype EmptyAPI Source # | |
(HasForeign k lang ftype a, HasForeign k lang ftype b) => HasForeign k lang ftype ((:<|>) a b) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * (Description desc) api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * (Summary desc) api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * HttpVersion api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype (WithNamedContext name context api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * Vault api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * IsSecure api) Source # | |
HasForeign k lang ftype api => HasForeign k lang ftype ((:>) * RemoteHost api) Source # | |
(KnownSymbol path, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) Symbol path api) Source # | |
(Elem * JSON list, HasForeignType k * lang ftype a, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * (ReqBody' mods list a) api) Source # | |
(KnownSymbol sym, HasForeignType k * lang ftype Bool, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * (QueryFlag sym) api) Source # | |
(KnownSymbol sym, HasForeignType k * lang ftype [a], HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * (QueryParams sym a) api) Source # | |
(KnownSymbol sym, HasForeignType k * lang ftype (RequiredArgument mods a), HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * (QueryParam' mods sym a) api) Source # | |
(KnownSymbol sym, HasForeignType k * lang ftype (RequiredArgument mods a), HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * (Header' * mods sym a) api) Source # | |
(KnownSymbol sym, HasForeignType k * lang ftype [t], HasForeign k lang ftype sublayout) => HasForeign k lang ftype ((:>) * (CaptureAll sym t) sublayout) Source # | |
(KnownSymbol sym, HasForeignType k * lang ftype t, HasForeign k lang ftype api) => HasForeign k lang ftype ((:>) * (Capture' mods sym t) api) Source # | |
(Elem * JSON list, HasForeignType k * lang ftype a, ReflectMethod k1 method) => HasForeign k lang ftype (Verb k1 method status list a) Source # | |
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 #
GenerateList ftype EmptyForeignAPI Source # | |
GenerateList ftype (Req ftype) Source # | |
(GenerateList ftype start, GenerateList ftype rest) => GenerateList ftype ((:<|>) start rest) 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