From 94cccffc75819ca8ea3b3f9f7a19b794bca4ca5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Deest?= Date: Thu, 30 Sep 2021 18:16:47 +0200 Subject: [PATCH] Add NamedRoutes combinator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- servant/src/Servant/API/Generic.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/servant/src/Servant/API/Generic.hs b/servant/src/Servant/API/Generic.hs index b887c09e..6262e539 100644 --- a/servant/src/Servant/API/Generic.hs +++ b/servant/src/Servant/API/Generic.hs @@ -37,6 +37,8 @@ module Servant.API.Generic ( ToServant, toServant, fromServant, + -- * NamedRoutes combinator + NamedRoutes, -- * AsApi AsApi, ToServantApi, @@ -120,6 +122,9 @@ genericApi -> Proxy (ToServantApi routes) genericApi _ = Proxy +-- | Combinator for embedding a record of named routes into a Servant API type. +data NamedRoutes (api :: * -> *) + ------------------------------------------------------------------------------- -- Class -------------------------------------------------------------------------------