Add NamedRoutes combinator

Allows users to directly embed APIs defined as records of routes into
vanilla Servant API types.

E.g.:

```haskell
data MyRoutes mode = MyRoutes
  { version :: mode :- Get '[JSON] Int
  , …
  }

type API = "prefix" :> NamedRoutes MyRoutes :<|> …
```

APIs can thus be recursively defined directly with Generic record types.
This commit is contained in:
Gaël Deest 2021-09-30 18:16:47 +02:00
parent 0b706aa6d1
commit 94cccffc75

View file

@ -37,6 +37,8 @@ module Servant.API.Generic (
ToServant, ToServant,
toServant, toServant,
fromServant, fromServant,
-- * NamedRoutes combinator
NamedRoutes,
-- * AsApi -- * AsApi
AsApi, AsApi,
ToServantApi, ToServantApi,
@ -120,6 +122,9 @@ genericApi
-> Proxy (ToServantApi routes) -> Proxy (ToServantApi routes)
genericApi _ = Proxy genericApi _ = Proxy
-- | Combinator for embedding a record of named routes into a Servant API type.
data NamedRoutes (api :: * -> *)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Class -- Class
------------------------------------------------------------------------------- -------------------------------------------------------------------------------