Full description of an endpoint in your API, generated by listFromAPI. It should give you all the information needed to generate foreign language bindings.
Every field containing ftype will use the foreign type mapping specified via HasForeignType (see its docstring on how to set that up).
The content type the request body is transferred as.
This is a severe limitation of servant-foreign currently,
as we only allow the content type to be JSON
no user-defined content types. (ReqBodyMultipart is not
actually implemented.)
Thus, any routes looking like this will work:
"foo" :> Get '[JSON] Foo
while routes like
"foo" :> Get '[MyFancyContentType] Foo
will fail with an error like
• JSON expected in list '[MyFancyContentType]
Instances4GenerateList, Eq, Data, Show
GenerateListftype (Reqftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
Eqftype => Eq (Reqftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
Dataftype => Data (Reqftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
Showftype => Show (Reqftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
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 ftype _ = "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