From 65e3070cacccb02502e8c24b3222a0532e3f4397 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 -------------------------------------------------------------------------------