{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Servant.Server
(
serve
, serveWithContext
,
toApplication
,
HasServer(..)
, Server
, EmptyServer
, emptyServer
, Handler (..)
, runHandler
, layout
, layoutWithContext
, hoistServer
, tweakResponse
, Context(..)
, HasContextEntry(getContextEntry)
, NamedContext(..)
, descendIntoNamedContext
, BasicAuthCheck(BasicAuthCheck, unBasicAuthCheck)
, BasicAuthResult(..)
, ServerError(..)
, err300
, err301
, err302
, err303
, err304
, err305
, err307
, err400
, err401
, err402
, err403
, err404
, err405
, err406
, err407
, err409
, err410
, err411
, err412
, err413
, err414
, err415
, err416
, err417
, err418
, err422
, err500
, err501
, err502
, err503
, err504
, err505
, Application
, Tagged (..)
) where
import Data.Proxy
(Proxy (..))
import Data.Tagged
(Tagged (..))
import Data.Text
(Text)
import Network.Wai
(Application)
import Servant.Server.Internal
serve :: (HasServer api '[]) => Proxy api -> Server api -> Application
serve :: Proxy api -> Server api -> Application
serve p :: Proxy api
p = Proxy api -> Context '[] -> Server api -> Application
forall api (context :: [*]).
HasServer api context =>
Proxy api -> Context context -> Server api -> Application
serveWithContext Proxy api
p Context '[]
EmptyContext
serveWithContext :: (HasServer api context)
=> Proxy api -> Context context -> Server api -> Application
serveWithContext :: Proxy api -> Context context -> Server api -> Application
serveWithContext p :: Proxy api
p context :: Context context
context server :: Server api
server =
RoutingApplication -> Application
toApplication (Router () -> RoutingApplication
runRouter (Proxy api
-> Context context -> Delayed () (Server api) -> Router ()
forall k (api :: k) (context :: [*]) env.
HasServer api context =>
Proxy api
-> Context context -> Delayed env (Server api) -> Router env
route Proxy api
p Context context
context (RouteResult (Server api) -> Delayed () (Server api)
forall a env. RouteResult a -> Delayed env a
emptyDelayed (Server api -> RouteResult (Server api)
forall a. a -> RouteResult a
Route Server api
server))))
hoistServer :: (HasServer api '[]) => Proxy api
-> (forall x. m x -> n x) -> ServerT api m -> ServerT api n
hoistServer :: Proxy api
-> (forall x. m x -> n x) -> ServerT api m -> ServerT api n
hoistServer p :: Proxy api
p = Proxy api
-> Proxy '[]
-> (forall x. m x -> n x)
-> ServerT api m
-> ServerT api n
forall k (api :: k) (context :: [*]) (m :: * -> *) (n :: * -> *).
HasServer api context =>
Proxy api
-> Proxy context
-> (forall x. m x -> n x)
-> ServerT api m
-> ServerT api n
hoistServerWithContext Proxy api
p (Proxy '[]
forall k (t :: k). Proxy t
Proxy :: Proxy '[])
layout :: (HasServer api '[]) => Proxy api -> Text
layout :: Proxy api -> Text
layout p :: Proxy api
p = Proxy api -> Context '[] -> Text
forall api (context :: [*]).
HasServer api context =>
Proxy api -> Context context -> Text
layoutWithContext Proxy api
p Context '[]
EmptyContext
layoutWithContext :: (HasServer api context)
=> Proxy api -> Context context -> Text
layoutWithContext :: Proxy api -> Context context -> Text
layoutWithContext p :: Proxy api
p context :: Context context
context =
Router' Any RoutingApplication -> Text
forall env a. Router' env a -> Text
routerLayout (Proxy api
-> Context context
-> Delayed Any (Server api)
-> Router' Any RoutingApplication
forall k (api :: k) (context :: [*]) env.
HasServer api context =>
Proxy api
-> Context context -> Delayed env (Server api) -> Router env
route Proxy api
p Context context
context (RouteResult (Server api) -> Delayed Any (Server api)
forall a env. RouteResult a -> Delayed env a
emptyDelayed (ServerError -> RouteResult (Server api)
forall a. ServerError -> RouteResult a
FailFatal ServerError
err501)))