HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleservant-foreign-0.16.1Haskell2010

Servant.Foreign.Internal

  • 14 types
  • 3 classes
  • 32 values
newtypenewtype FunctionName
#

Canonical name of the endpoint, can be used to generate a function name.

You can use the functions in Servant.Foreign.Inflections, like camelCase to transform to Text.

Instances5Eq, Data, Show, Semigroup, Monoid
newtypenewtype PathSegment
#

See documentation of Arg

Instances6Eq, Data, Show, IsString, Semigroup, Monoid
datadata Arg ftype
#

Maps a name to the foreign type that belongs to the annotated value.

Used for header args, query args, and capture args.

Constructors

  • Arg
    • _argName :: PathSegment

      The name to be captured.

      Only for capture args it really denotes a path segment.

    • _argType :: ftype

      Foreign type the associated value will have

Instances3Eq, Data, Show
  • Eq ftype => Eq (Arg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (Arg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (Arg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
datadata SegmentType ftype
#

Constructors

  • Static PathSegment

    Static path segment.

    "foo/bar/baz"

    contains the static segments "foo", "bar" and "baz".

  • Cap (Arg ftype)

    A capture.

    "user/{userid}/name"

    would capture the arg userid with type ftype.

Instances3Eq, Data, Show
  • Eq ftype => Eq (SegmentType ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (SegmentType ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (SegmentType ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
newtypenewtype Segment ftype
#

A part of the Url’s path.

Constructors

Instances3Eq, Data, Show
  • Eq ftype => Eq (Segment ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (Segment ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (Segment ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
datadata ArgType
#

Type of a QueryArg.

Instances3Eq, Data, Show
  • Eq ArgTypeDefined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ArgTypeDefined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ArgTypeDefined in servant-foreign-0.16.1 · Servant.Foreign.Internal
datadata QueryArg ftype
#

Url Query argument.

Urls can contain query arguments, which is a list of key-value pairs. In a typical url, query arguments look like this:

?foo=bar&alist[]=el1&alist[]=el2&aflag

Each pair can be

  • ?foo=bar: a plain key-val pair, either optional or required (QueryParam)

  • ?aflag: a flag (no value, implicitly Bool with default false if it’s missing) (QueryFlag)

  • ?alist[]=el1&alist[]=el2: list of values (QueryParams)

_queryArgType will be set accordingly.

For the plain key-val pairs (QueryParam), _queryArgName’s ftype will be wrapped in a Maybe if the argument is optional.

Constructors

Instances3Eq, Data, Show
  • Eq ftype => Eq (QueryArg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (QueryArg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (QueryArg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
datadata HeaderArg ftype
#

Constructors

Instances3Eq, Data, Show
  • Eq ftype => Eq (HeaderArg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (HeaderArg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (HeaderArg ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
datadata Url ftype
#

Full endpoint url, with all captures and parameters

Constructors

  • Url
    • _path :: Path ftype

      Url path, list of either static segments or captures

      "foo/{id}/bar"
    • _queryStr :: [QueryArg ftype]

      List of query args

      "?foo=bar&a=b"
    • _frag :: Maybe ftype

      Url fragment.

      Not sent to the HTTP server, so only useful for frontend matters (e.g. inter-page linking).

      #fragmentText
Instances3Eq, Data, Show
  • Eq ftype => Eq (Url ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (Url ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (Url ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
datadata Req ftype
#

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

See https://docs.servant.dev/en/stable/tutorial/ApiType.html for accessible documentation of the possible content of an endpoint.

Constructors

  • Req
    • _reqUrl :: Url ftype

      Full list of URL segments, including captures

    • _reqMethod :: Method

      "GET"/"POST"/"PUT"/…

    • _reqHeaders :: [HeaderArg ftype]

      Headers required by this endpoint, with their type

    • _reqBody :: Maybe ftype

      Foreign type of the expected request body (ReqBody), if any

    • _reqReturnType :: Maybe ftype

      The foreign type of the response, if any

    • _reqFuncName :: FunctionName

      The URL segments rendered in a way that they can be easily concatenated into a canonical function name

    • _reqBodyContentType :: ReqBodyContentType

      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
  • GenerateList ftype (Req ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Eq ftype => Eq (Req ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Data ftype => Data (Req ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
  • Show ftype => Show (Req ftype)Defined in servant-foreign-0.16.1 · Servant.Foreign.Internal
classclass HasForeignType (lang :: k) ftype (a :: k1) where
#

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

Methods

Instances1HasForeignType
datadata NoTypes
#

The language definition without any foreign types. It can be used for dynamic languages which do not do type annotations.

Instances1HasForeignType
classclass HasForeign (lang :: k) ftype api where
#

Implementation of the Servant framework types.

Relevant instances: Everything containing HasForeignType.

Associated types

Methods

Instances25HasForeign, …
classclass GenerateList ftype reqs where
#

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.

Methods

Instances3GenerateList