From 94483d586cf946f5b6b28e834f4ea14a94e0ec7f Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 16 May 2017 09:34:07 +0000 Subject: [PATCH] Add `instance HasServer EmptyAPI` --- doc/tutorial/Server.lhs | 9 +++++++++ servant-server/src/Servant/Server.hs | 2 ++ servant-server/src/Servant/Server/Internal.hs | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/tutorial/Server.lhs b/doc/tutorial/Server.lhs index 0de0907b..9b81d30e 100644 --- a/doc/tutorial/Server.lhs +++ b/doc/tutorial/Server.lhs @@ -1020,6 +1020,15 @@ serverFor = error "..." -- or the mailing list if you get stuck! ``` +TODO prose + +``` haskell +type CombinedAPI2 = CombinedAPI :<|> EmptyAPI + +server11 :: Server CombinedAPI2 +server11 = server10 :<|> emptyAPIServer +``` + ## Using another monad for your handlers Remember how `Server` turns combinators for HTTP methods into `Handler`? Well, actually, there's more to that. `Server` is actually a diff --git a/servant-server/src/Servant/Server.hs b/servant-server/src/Servant/Server.hs index 47fdf0cf..212277e2 100644 --- a/servant-server/src/Servant/Server.hs +++ b/servant-server/src/Servant/Server.hs @@ -17,6 +17,8 @@ module Servant.Server , -- * Handlers for all standard combinators HasServer(..) , Server + , EmptyAPIServer + , emptyAPIServer , Handler (..) , runHandler diff --git a/servant-server/src/Servant/Server/Internal.hs b/servant-server/src/Servant/Server/Internal.hs index 31d7b751..fc2c80c0 100644 --- a/servant-server/src/Servant/Server/Internal.hs +++ b/servant-server/src/Servant/Server/Internal.hs @@ -32,7 +32,7 @@ import Data.Maybe (fromMaybe, mapMaybe) import Data.Either (partitionEithers) import Data.String (fromString) import Data.String.Conversions (cs, (<>)) -import Data.Tagged (Tagged, untag) +import Data.Tagged (Tagged(..), untag) import qualified Data.Text as T import Data.Typeable import GHC.TypeLits (KnownNat, KnownSymbol, natVal, @@ -52,7 +52,7 @@ import Web.HttpApiData (FromHttpApiData, parseHeader, parseUrlPieceMaybe, parseUrlPieces) import Servant.API ((:<|>) (..), (:>), BasicAuth, Capture, - CaptureAll, Verb, + CaptureAll, Verb, EmptyAPI, ReflectMethod(reflectMethod), IsSecure(..), Header, QueryFlag, QueryParam, QueryParams, Raw, @@ -532,6 +532,16 @@ instance HasServer api context => HasServer (HttpVersion :> api) context where route Proxy context subserver = route (Proxy :: Proxy api) context (passToServer subserver httpVersion) +data EmptyAPIServer = EmptyAPIServer + +emptyAPIServer :: Server EmptyAPI +emptyAPIServer = Tagged EmptyAPIServer + +instance HasServer EmptyAPI context where + type ServerT EmptyAPI m = Tagged m EmptyAPIServer + + route Proxy _ _ = StaticRouter mempty mempty + -- | Basic Authentication instance ( KnownSymbol realm , HasServer api context