-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A family of combinators for defining webservices APIs and serving them -- -- Interpret a Servant API as a Snap server, using any Snaplets you like. -- -- You can learn about the basics of servant in the Servant -- tutorial, and about the basics of Snap at the Snaplets -- tutorial -- -- Here is a runnable example, with comments, that defines a dummy -- API and implements a webserver that serves this API, using this -- package. One route delegates to the Auth snaplet, another -- delegates to Heist. -- -- CHANGELOG @package servant-snap @version 0.8.3 module Servant.Server.Internal.Context -- | Contexts are used to pass values to combinators. (They are -- not meant to be used to pass parameters to your handlers, i.e. -- they should not replace any custom ReaderT-monad-stack that -- you're using with Enter.) If you don't use combinators that -- require any context entries, you can just use serve as always. -- -- If you are using combinators that require a non-empty Context -- you have to use serveWithContext and pass it a Context -- that contains all the values your combinators need. A Context -- is essentially a heterogenous list and accessing the elements is being -- done by type (see getContextEntry). The parameter of the type -- Context is a type-level list reflecting the types of the -- contained context entries. To create a Context with entries, -- use the operator (:.): -- --
--   >>> :type True :. () :. EmptyContext
--   True :. () :. EmptyContext :: Context '[Bool, ()]
--   
data Context contextTypes [EmptyContext] :: Context '[] [:.] :: x -> Context xs -> Context (x : xs) infixr 5 :. -- | This class is used to access context entries in Contexts. -- getContextEntry returns the first value where the type matches: -- --
--   >>> getContextEntry (True :. False :. EmptyContext) :: Bool
--   True
--   
-- -- If the Context does not contain an entry of the requested type, -- you'll get an error: -- --
--   >>> getContextEntry (True :. False :. EmptyContext) :: String
--   ...
--   ...No instance for (HasContextEntry '[] [Char])
--   ...
--   
class HasContextEntry (context :: [*]) (val :: *) getContextEntry :: HasContextEntry context val => Context context -> val -- | Normally context entries are accessed by their types. In case you need -- to have multiple values of the same type in your Context and -- need to access them, we provide NamedContext. You can think of -- it as sub-namespaces for Contexts. data NamedContext (name :: Symbol) (subContext :: [*]) NamedContext :: Context subContext -> NamedContext -- | descendIntoNamedContext allows you to access -- NamedContexts. Usually you won't have to use it yourself but -- instead use a combinator like WithNamedContext. -- -- This is how descendIntoNamedContext works: -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> let subContext = True :. EmptyContext
--   
--   >>> :type subContext
--   subContext :: Context '[Bool]
--   
--   >>> let parentContext = False :. (NamedContext subContext :: NamedContext "subContext" '[Bool]) :. EmptyContext
--   
--   >>> :type parentContext
--   parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]
--   
--   >>> descendIntoNamedContext (Proxy :: Proxy "subContext") parentContext :: Context '[Bool]
--   True :. EmptyContext
--   
descendIntoNamedContext :: forall context name subContext. HasContextEntry context (NamedContext name subContext) => Proxy (name :: Symbol) -> Context context -> Context subContext instance Servant.Server.Internal.Context.HasContextEntry xs val => Servant.Server.Internal.Context.HasContextEntry (notIt : xs) val instance Servant.Server.Internal.Context.HasContextEntry (val : xs) val instance GHC.Show.Show (Servant.Server.Internal.Context.Context '[]) instance (GHC.Show.Show a, GHC.Show.Show (Servant.Server.Internal.Context.Context as)) => GHC.Show.Show (Servant.Server.Internal.Context.Context (a : as)) instance GHC.Classes.Eq (Servant.Server.Internal.Context.Context '[]) instance (GHC.Classes.Eq a, GHC.Classes.Eq (Servant.Server.Internal.Context.Context as)) => GHC.Classes.Eq (Servant.Server.Internal.Context.Context (a : as)) module Servant.Server.Internal.PathInfo rqPath :: Request -> ByteString pathInfo :: Request -> [Text] pathSafeTail :: Request -> ([ByteString], [ByteString]) reqSafeTail :: Request -> Request reqNoPath :: Request -> Request -- | Like `null . pathInfo`, but works with redundant trailing slashes. pathIsEmpty :: Request -> Bool splitMatrixParameters :: Text -> (Text, Text) parsePathInfo :: Request -> [Text] -- | Returns a processed pathInfo from the request. -- -- In order to handle matrix parameters in the request correctly, the raw -- pathInfo needs to be processed, so routing works as intended. Therefor -- this function should be used to access the pathInfo for routing -- purposes. processedPathInfo :: Request -> [Text] module Servant.Server.Internal.ServantErr data ServantErr ServantErr :: Int -> String -> ByteString -> [Header] -> ServantErr [errHTTPCode] :: ServantErr -> Int [errReasonPhrase] :: ServantErr -> String [errBody] :: ServantErr -> ByteString [errHeaders] :: ServantErr -> [Header] setHeaders :: [Header] -> Response -> Response responseServantErr :: ServantErr -> Response -- | Terminate request handling with a ServantErr via -- finishWith throwError :: MonadSnap m => ServantErr -> m a err300 :: ServantErr err301 :: ServantErr err302 :: ServantErr err303 :: ServantErr err304 :: ServantErr err305 :: ServantErr err307 :: ServantErr err400 :: ServantErr err401 :: ServantErr err402 :: ServantErr err403 :: ServantErr err404 :: ServantErr err405 :: ServantErr err406 :: ServantErr err407 :: ServantErr err409 :: ServantErr err410 :: ServantErr err411 :: ServantErr err412 :: ServantErr err413 :: ServantErr err414 :: ServantErr err415 :: ServantErr err416 :: ServantErr err417 :: ServantErr err500 :: ServantErr err501 :: ServantErr err502 :: ServantErr err503 :: ServantErr err504 :: ServantErr err505 :: ServantErr instance GHC.Read.Read Servant.Server.Internal.ServantErr.ServantErr instance GHC.Classes.Eq Servant.Server.Internal.ServantErr.ServantErr instance GHC.Show.Show Servant.Server.Internal.ServantErr.ServantErr module Servant.Server.Internal.SnapShims type Application m = Request -> (Response -> m Response) -> m Response snapToApplication :: MonadSnap m => m () -> Application m snapToApplication' :: MonadSnap m => m a -> Application m applicationToSnap :: MonadSnap m => Application m -> m () addHeaders :: HasHeaders a => a -> Headers -> a unSnapMethod :: Method -> ByteString ok200 :: Status noContent204 :: Status created201 :: Status badRequest400 :: Status notFound404 :: Status methodNotAllowed405 :: Status unsupportedMediaType415 :: Status initThunk :: IO a -> IO (IO a) module Servant.Server.Internal.RoutingApplication type RoutingApplication m = Request " the request, the field 'pathInfo' may be modified by url routing" -> (RouteResult Response -> m Response) -> m Response -- | The result of matching against a path in the route tree. data RouteResult a -- | Keep trying other paths. The ServantErr should only be 404, -- 405 or 406. Fail :: ServantErr -> RouteResult a -- | Don't try other paths. FailFatal :: !ServantErr -> RouteResult a Route :: !a -> RouteResult a toApplication :: forall m. MonadSnap m => RoutingApplication m -> Application m responseLBS :: Status -> [(CI ByteString, ByteString)] -> ByteString -> Response runAction :: MonadSnap m => Delayed m env (m a) -> env -> Request -> (RouteResult Response -> m r) -> (a -> RouteResult Response) -> m r data Delayed m env c [Delayed] :: {capturesD :: env -> DelayedM m captures, methodD :: DelayedM m (), authD :: DelayedM m auth, acceptD :: DelayedM m (), contentD :: DelayedM m contentType, paramsD :: DelayedM m params, headersD :: DelayedM m headers, bodyD :: contentType -> DelayedM m body, serverD :: captures -> params -> headers -> auth -> body -> Request -> RouteResult c} -> Delayed m env c newtype DelayedM m a DelayedM :: (Request -> m (RouteResult a)) -> DelayedM m a [runDelayedM] :: DelayedM m a -> Request -> m (RouteResult a) -- | A Delayed without any stored checks. emptyDelayed :: Monad m => Proxy (m :: * -> *) -> RouteResult a -> Delayed m env a -- | Fail with the option to recover. delayedFail :: Monad m => ServantErr -> DelayedM m a -- | Fail fatally, i.e., without any option to recover. delayedFailFatal :: Monad m => ServantErr -> DelayedM m a -- | Gain access to the incoming request. withRequest :: (Request -> DelayedM m a) -> DelayedM m a -- | Add a capture to the end of the capture block. addCapture :: forall env a b captured m. Monad m => Delayed m env (a -> b) -> (captured -> DelayedM m a) -> Delayed m (captured, env) b -- | Add a parameter check to the end of the params block addParameterCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b -- | Add a header check to the end of the headers block addHeaderCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b -- | Add a method check to the end of the method block. addMethodCheck :: Monad m => Delayed m env a -> DelayedM m () -> Delayed m env a -- | Add an auth check to the end of the auth block. addAuthCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b -- | Add a content type and body checks around parameter checks. -- -- We'll report failed content type check (415), before trying to parse -- query parameters (400). Which, in turn, happens before request body -- parsing. addBodyCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m c -> (c -> DelayedM m a) -> Delayed m env b -- | Add an accept header check before handling parameters. In principle, -- we'd like to take a bad body (400) response take precedence over a -- failed accept check (406). BUT to allow streaming the body, we cannot -- run the body check and then still backtrack. We therefore do the -- accept check before the body check, when we can still backtrack. There -- are other solutions to this, but they'd be more complicated (such as -- delaying the body check further so that it can still be run in a -- situation where we'd otherwise report 406). addAcceptCheck :: Monad m => Delayed m env a -> DelayedM m () -> Delayed m env a -- | Many combinators extract information that is passed to the handler -- without the possibility of failure. In such a case, -- passToServer can be used. passToServer :: Delayed m env (a -> b) -> (Request -> a) -> Delayed m env b -- | Run a delayed server. Performs all scheduled operations in order, and -- passes the results from the capture and body blocks on to the actual -- handler. -- -- This should only be called once per request; otherwise the guarantees -- about effect and HTTP error ordering break down. runDelayed :: Monad m => Delayed m env a -> env -> Request -> m (RouteResult a) instance GHC.Base.Functor Servant.Server.Internal.RoutingApplication.RouteResult instance GHC.Read.Read a => GHC.Read.Read (Servant.Server.Internal.RoutingApplication.RouteResult a) instance GHC.Show.Show a => GHC.Show.Show (Servant.Server.Internal.RoutingApplication.RouteResult a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Servant.Server.Internal.RoutingApplication.RouteResult a) instance GHC.Base.Functor (Servant.Server.Internal.RoutingApplication.Delayed m env) instance GHC.Base.Monad m => GHC.Base.Functor (Servant.Server.Internal.RoutingApplication.DelayedM m) instance GHC.Base.Monad m => GHC.Base.Applicative (Servant.Server.Internal.RoutingApplication.DelayedM m) instance GHC.Base.Monad m => GHC.Base.Monad (Servant.Server.Internal.RoutingApplication.DelayedM m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Servant.Server.Internal.RoutingApplication.DelayedM m) instance (GHC.Base.Monad m, Snap.Internal.Core.MonadSnap m) => GHC.Base.Alternative (Servant.Server.Internal.RoutingApplication.DelayedM m) instance Control.Monad.Trans.Class.MonadTrans Servant.Server.Internal.RoutingApplication.DelayedM module Servant.Server.Internal.Router type Router (m :: * -> *) env = Router' m env (RoutingApplication m) -- | Internal representation of a router. data Router' (m :: * -> *) env a StaticRouter :: Map Text (Router' m env a) -> [env -> a] -> Router' env a CaptureRouter :: Router' m (Text, env) a -> Router' env a CaptureAllRouter :: Router' m ([Text], env) a -> Router' env a RawRouter :: (env -> a) -> Router' env a Choice :: Router' m env a -> Router' m env a -> Router' env a pathRouter :: Text -> Router' m env a -> Router' m env a leafRouter :: (env -> a) -> Router' m env a -- | Smart constructor for the choice between routers. We currently -- optimize the following cases: -- -- choice :: MonadSnap m => Router' m env a -> Router' m env a -> Router' m env a data RouterStructure StaticRouterStructure :: Map Text RouterStructure -> Int -> RouterStructure CaptureRouterStructure :: RouterStructure -> RouterStructure RawRouterStructure :: RouterStructure ChoiceStructure :: RouterStructure -> RouterStructure -> RouterStructure routerStructure :: Router' m env a -> RouterStructure -- | Compare the structure of two routers. sameStructure :: Router' m env a -> Router' m env b -> Bool -- | Provide a textual representation of the structure of a router. routerLayout :: Router' m env a -> Text -- | Apply a transformation to the response of a Router. tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router m env -> Router m env runRouter :: MonadSnap m => Router m () -> RoutingApplication m -- | Interpret a router as an application. runRouterEnv :: MonadSnap m => Router m env -> env -> RoutingApplication m runChoice :: [env -> RoutingApplication m] -> env -> RoutingApplication m worseHTTPCode :: Int -> Int -> Bool instance GHC.Show.Show Servant.Server.Internal.Router.RouterStructure instance GHC.Classes.Eq Servant.Server.Internal.Router.RouterStructure instance GHC.Base.Functor (Servant.Server.Internal.Router.Router' m env) module Servant.Server.Internal.BasicAuth -- | servant-server's current implementation of basic authentication is not -- immune to certian kinds of timing attacks. Decoding payloads does not -- take a fixed amount of time. -- -- The result of authentication/authorization data BasicAuthResult usr Unauthorized :: BasicAuthResult usr BadPassword :: BasicAuthResult usr NoSuchUser :: BasicAuthResult usr Authorized :: usr -> BasicAuthResult usr -- | Datatype wrapping a function used to check authentication. newtype BasicAuthCheck m usr BasicAuthCheck :: (BasicAuthData -> m (BasicAuthResult usr)) -> BasicAuthCheck m usr [unBasicAuthCheck] :: BasicAuthCheck m usr -> BasicAuthData -> m (BasicAuthResult usr) -- | Internal method to make a basic-auth challenge mkBAChallengerHdr :: ByteString -> (CI ByteString, ByteString) -- | Find and decode an Authorization header from the request as -- Basic Auth decodeBAHdr :: Request -> Maybe BasicAuthData -- | Run and check basic authentication, returning the appropriate http -- error per the spec. runBasicAuth :: MonadSnap m => Request -> ByteString -> BasicAuthCheck m usr -> DelayedM m usr instance GHC.Base.Functor m => GHC.Base.Functor (Servant.Server.Internal.BasicAuth.BasicAuthCheck m) instance GHC.Generics.Generic (Servant.Server.Internal.BasicAuth.BasicAuthCheck m usr) instance GHC.Base.Functor Servant.Server.Internal.BasicAuth.BasicAuthResult instance GHC.Generics.Generic (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) instance GHC.Read.Read usr => GHC.Read.Read (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) instance GHC.Show.Show usr => GHC.Show.Show (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) instance GHC.Classes.Eq usr => GHC.Classes.Eq (Servant.Server.Internal.BasicAuth.BasicAuthResult usr) module Servant.Server.Internal -- | Singleton type representing a server that serves an empty API. data EmptyServer EmptyServer :: EmptyServer type Server api context m = ServerT api context m class HasServer api context (m :: * -> *) where { type family ServerT api context m :: *; } route :: (HasServer api context m, MonadSnap m) => Proxy api -> Context context -> Delayed m env (Server api context m) -> Router m env hoistServerWithContext :: HasServer api context m => proxy api -> proxy' context -> (forall x. m x -> n x) -> ServerT api context m -> ServerT api context n captured :: FromHttpApiData a => proxy (Capture' mods sym a) -> Text -> Maybe a allowedMethodHead :: Method -> Request -> Bool allowedMethod :: Method -> Request -> Bool processMethodRouter :: Maybe (ByteString, ByteString) -> Status -> Method -> Maybe [(HeaderName, ByteString)] -> Request -> RouteResult Response methodCheck :: MonadSnap m => Method -> Request -> DelayedM m () acceptCheck :: (AllMime list, MonadSnap m) => Proxy list -> ByteString -> DelayedM m () methodRouter :: (AllCTRender ctypes a, MonadSnap m) => Method -> Proxy ctypes -> Status -> Delayed m env (m a) -> Router m env methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v, MonadSnap m) => Method -> Proxy ctypes -> Status -> Delayed m env (m (Headers h v)) -> Router m env streamRouter :: (MimeRender ctype a, FramingRender framing ctype, ToStreamGenerator b a, MonadSnap m) => (c -> ([(HeaderName, ByteString)], b)) -> Method -> Status -> Proxy framing -> Proxy ctype -> Delayed m env (m c) -> Router m env -- | Server for EmptyAPI emptyServer :: ServerT EmptyAPI context m ct_wildcard :: ByteString instance GHC.Enum.Enum Servant.Server.Internal.EmptyServer instance GHC.Enum.Bounded Servant.Server.Internal.EmptyServer instance GHC.Show.Show Servant.Server.Internal.EmptyServer instance GHC.Classes.Eq Servant.Server.Internal.EmptyServer instance Servant.Server.Internal.HasServer Servant.API.Empty.EmptyAPI context m instance (Servant.Server.Internal.HasServer a ctx m, Servant.Server.Internal.HasServer b ctx m) => Servant.Server.Internal.HasServer (a Servant.API.Alternative.:<|> b) ctx m instance (Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context m) => Servant.Server.Internal.HasServer (Servant.API.Capture.Capture' mods capture a Servant.API.Sub.:> api) context m instance (Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context m) => Servant.Server.Internal.HasServer (Servant.API.Capture.CaptureAll capture a Servant.API.Sub.:> api) context m instance forall k1 (ctypes :: [*]) a (method :: k1) (status :: GHC.Types.Nat) (context :: [*]) (m :: * -> *). (Servant.API.ContentTypes.AllCTRender ctypes a, Servant.API.Verbs.ReflectMethod method, GHC.TypeNats.KnownNat status) => Servant.Server.Internal.HasServer (Servant.API.Verbs.Verb method status ctypes a) context m instance forall k1 (ctypes :: [*]) a (method :: k1) (status :: GHC.Types.Nat) (h :: [*]) (context :: [*]) (m :: * -> *). (Servant.API.ContentTypes.AllCTRender ctypes a, Servant.API.Verbs.ReflectMethod method, GHC.TypeNats.KnownNat status, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers h a)) => Servant.Server.Internal.HasServer (Servant.API.Verbs.Verb method status ctypes (Servant.API.ResponseHeaders.Headers h a)) context m instance forall k1 ctype a (method :: k1) (status :: GHC.Types.Nat) framing b (context :: [*]) (m :: * -> *). (Servant.API.ContentTypes.MimeRender ctype a, Servant.API.Verbs.ReflectMethod method, GHC.TypeNats.KnownNat status, Servant.API.Stream.FramingRender framing ctype, Servant.API.Stream.ToStreamGenerator b a) => Servant.Server.Internal.HasServer (Servant.API.Stream.Stream method status framing ctype b) context m instance forall k1 ctype a (method :: k1) (status :: GHC.Types.Nat) framing b (h :: [*]) (context :: [*]) (m :: * -> *). (Servant.API.ContentTypes.MimeRender ctype a, Servant.API.Verbs.ReflectMethod method, GHC.TypeNats.KnownNat status, Servant.API.Stream.FramingRender framing ctype, Servant.API.Stream.ToStreamGenerator b a, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers h b)) => Servant.Server.Internal.HasServer (Servant.API.Stream.Stream method status framing ctype (Servant.API.ResponseHeaders.Headers h b)) context m instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context m, Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldRequired mods), Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldLenient mods)) => Servant.Server.Internal.HasServer (Servant.API.Header.Header' mods sym a Servant.API.Sub.:> api) context m instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context m, Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldRequired mods), Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldLenient mods)) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryParam' mods sym a Servant.API.Sub.:> api) context m instance (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.FromHttpApiData a, Servant.Server.Internal.HasServer api context m) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryParams sym a Servant.API.Sub.:> api) context m instance (GHC.TypeLits.KnownSymbol sym, Servant.Server.Internal.HasServer api context m) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryFlag sym Servant.API.Sub.:> api) context m instance Servant.Server.Internal.HasServer Servant.API.Raw.Raw context m instance (Servant.API.ContentTypes.AllCTUnrender list a, Servant.Server.Internal.HasServer api context m, Data.Singletons.Bool.SBoolI (Servant.API.Modifiers.FoldLenient mods), Snap.Internal.Core.MonadSnap m) => Servant.Server.Internal.HasServer (Servant.API.ReqBody.ReqBody' mods list a Servant.API.Sub.:> api) context m instance (GHC.TypeLits.KnownSymbol path, Servant.Server.Internal.HasServer api context m) => Servant.Server.Internal.HasServer (path Servant.API.Sub.:> api) context m instance Servant.Server.Internal.HasServer api context m => Servant.Server.Internal.HasServer (Servant.API.RemoteHost.RemoteHost Servant.API.Sub.:> api) context m instance Servant.Server.Internal.HasServer api context m => Servant.Server.Internal.HasServer (Servant.API.IsSecure.IsSecure Servant.API.Sub.:> api) context m instance Servant.Server.Internal.HasServer api context m => Servant.Server.Internal.HasServer (Snap.Internal.Http.Types.HttpVersion Servant.API.Sub.:> api) context m instance Servant.Server.Internal.HasServer api ctx m => Servant.Server.Internal.HasServer (Servant.API.Description.Summary desc Servant.API.Sub.:> api) ctx m instance Servant.Server.Internal.HasServer api ctx m => Servant.Server.Internal.HasServer (Servant.API.Description.Description desc Servant.API.Sub.:> api) ctx m instance (GHC.TypeLits.KnownSymbol realm, Servant.Server.Internal.HasServer api context m, Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Internal.BasicAuth.BasicAuthCheck m usr)) => Servant.Server.Internal.HasServer (Servant.API.BasicAuth.BasicAuth realm usr Servant.API.Sub.:> api) context m -- | This module lets you implement Servers for defined APIs. You'll -- most likely just need serve. module Servant.Server serveSnap :: forall layout m. (HasServer layout '[] m, MonadSnap m) => Proxy layout -> Server layout '[] m -> m () serveSnapWithContext :: forall layout context m. (HasServer layout context m, MonadSnap m) => Proxy layout -> Context context -> Server layout context m -> m () class HasServer api context (m :: * -> *) where { type family ServerT api context m :: *; } route :: (HasServer api context m, MonadSnap m) => Proxy api -> Context context -> Delayed m env (Server api context m) -> Router m env hoistServerWithContext :: HasServer api context m => proxy api -> proxy' context -> (forall x. m x -> n x) -> ServerT api context m -> ServerT api context n type Server api context m = ServerT api context m data ServantErr ServantErr :: Int -> String -> ByteString -> [Header] -> ServantErr [errHTTPCode] :: ServantErr -> Int [errReasonPhrase] :: ServantErr -> String [errBody] :: ServantErr -> ByteString [errHeaders] :: ServantErr -> [Header] -- | Terminate request handling with a ServantErr via -- finishWith throwError :: MonadSnap m => ServantErr -> m a err300 :: ServantErr err301 :: ServantErr err302 :: ServantErr err303 :: ServantErr err304 :: ServantErr err305 :: ServantErr err307 :: ServantErr err400 :: ServantErr err401 :: ServantErr err402 :: ServantErr err403 :: ServantErr err404 :: ServantErr err405 :: ServantErr err406 :: ServantErr err407 :: ServantErr err409 :: ServantErr err410 :: ServantErr err411 :: ServantErr err412 :: ServantErr err413 :: ServantErr err414 :: ServantErr err415 :: ServantErr err416 :: ServantErr err417 :: ServantErr err500 :: ServantErr err501 :: ServantErr err502 :: ServantErr err503 :: ServantErr err504 :: ServantErr err505 :: ServantErr -- | This module defines a sever-side handler that lets you serve static -- files. -- -- module Servant.Utils.StaticFiles -- | Serve anything under the specified directory as a Raw endpoint. -- --
--   type MyApi = "static" :> Raw
--   
--   server :: Server MyApi
--   server = serveDirectory "/var/www"
--   
-- -- would capture any request to /static/<something> and -- look for <something> under /var/www. -- -- It will do its best to guess the MIME type for that file, based on the -- extension, and send an appropriate Content-Type header if -- possible. -- -- If your goal is to serve HTML, CSS and Javascript files that use the -- rest of the API as a webapp backend, you will most likely not want the -- static files to be hidden behind a /static/ prefix. In that -- case, remember to put the serveDirectory handler in the last -- position, because servant will try to match the handlers in -- order. serveDirectory :: MonadSnap m => FilePath -> Server Raw context m module Servant -- | Proxy is a type that holds no data, but has a phantom parameter -- of arbitrary type (or even kind). Its use is to provide type -- information, even though there is no value available of that type (or -- it may be too costly to create one). -- -- Historically, Proxy :: Proxy a is a safer -- alternative to the 'undefined :: a' idiom. -- --
--   >>> Proxy :: Proxy (Void, Int -> Int)
--   Proxy
--   
-- -- Proxy can even hold types of higher kinds, -- --
--   >>> Proxy :: Proxy Either
--   Proxy
--   
-- --
--   >>> Proxy :: Proxy Functor
--   Proxy
--   
-- --
--   >>> Proxy :: Proxy complicatedStructure
--   Proxy
--   
data Proxy (t :: k) :: forall k. () => k -> Type Proxy :: Proxy