Add helper functions

This commit is contained in:
Sasa Bogicevic 2018-04-27 11:34:03 +02:00
parent 4d46e98419
commit 3d9a151412

View file

@ -10,6 +10,8 @@ module Servant.Server
( -- * Run a wai application from an API ( -- * Run a wai application from an API
serve serve
, serveWithContext , serveWithContext
, fullyEvalResponse
, noEvalResponse
, -- * Construct a wai Application from an API , -- * Construct a wai Application from an API
toApplication toApplication
@ -124,16 +126,23 @@ import Servant.Server.Internal
-- --
serve :: (HasServer api '[Bool]) => Proxy api -> Server api -> Application serve :: (HasServer api '[Bool]) => Proxy api -> Server api -> Application
serve p = serveWithContext p (False :. EmptyContext) serve p = serveWithContext p noEvalResponse
serveWithContext :: (HasServer api context, HasContextEntry context Bool) serveWithContext :: (HasServer api context, HasContextEntry context Bool)
=> Proxy api -> Context context -> Server api -> Application => Proxy api -> Context context -> Server api -> Application
serveWithContext p context server = serveWithContext p context server =
toApplication toApplication
(getContextEntry context :: Bool) ((getContextEntry context :: Bool) || False)
-- ^ determins if we should fully evaluate response -- ^ determins if we should fully evaluate response
-- defaults to False
(runRouter (route p context (emptyDelayed (Route server)))) (runRouter (route p context (emptyDelayed (Route server))))
fullyEvalResponse :: Context '[Bool]
fullyEvalResponse = True :. EmptyContext
noEvalResponse :: Context '[Bool]
noEvalResponse = False :. EmptyContext
-- | Hoist server implementation. -- | Hoist server implementation.
-- --
-- Sometimes our cherished `Handler` monad isn't quite the type you'd like for -- Sometimes our cherished `Handler` monad isn't quite the type you'd like for