{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Web.Spock.Core
(
runSpock,
runSpockNoBanner,
spockAsApp,
spockT,
spockConfigT,
SpockT,
SpockCtxT,
Path,
root,
Var,
AltVar (..),
var,
static,
trailingSlash,
(<//>),
(<.>),
wildcard,
renderRoute,
renderRouteWith,
renderRouteEncoded,
renderRouteEncodedWith,
prehook,
get,
post,
getpost,
head,
put,
delete,
patch,
hookRoute,
hookRouteCustom,
hookAny,
hookAnyCustom,
hookRouteAll,
hookAnyAll,
Http.StdMethod (..),
middleware,
module Web.Spock.Action,
SpockConfig (..),
SlashPolicy (..),
defaultSpockConfig,
hookRoute',
hookAny',
SpockMethod (..),
W.HttpMethod (..),
)
where
import Control.Applicative
import Control.Monad.Reader
import Data.Foldable (forM_)
import Data.HVect hiding (head)
import qualified Data.Text as T
import qualified Network.HTTP.Types as Http
import Network.HTTP.Types.Method
import qualified Network.Wai as Wai
import qualified Network.Wai.Handler.Warp as Warp
import System.IO
import Web.HttpApiData
import Web.Routing.Combinators hiding (renderRoute, renderRouteWith, renderRouteEncoded, renderRouteEncodedWith)
import qualified Web.Routing.Combinators as COMB
import Web.Routing.Router (swapMonad)
import qualified Web.Routing.Router as AR
import Web.Routing.SafeRouting
import Web.Spock.Action
import Web.Spock.Internal.Config
import Web.Spock.Internal.Wire (SpockMethod (..))
import qualified Web.Spock.Internal.Wire as W
import Web.Spock.Routing
import Prelude hiding (curry, head, uncurry)
type SpockT = SpockCtxT ()
newtype LiftHooked ctx m = LiftHooked {forall ctx (m :: * -> *).
LiftHooked ctx m
-> forall a. ActionCtxT ctx m a -> ActionCtxT () m a
unLiftHooked :: forall a. ActionCtxT ctx m a -> ActionCtxT () m a}
injectHook :: LiftHooked ctx m -> (forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a) -> LiftHooked ctx' m
injectHook :: forall ctx (m :: * -> *) ctx'.
LiftHooked ctx m
-> (forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a)
-> LiftHooked ctx' m
injectHook (LiftHooked forall a. ActionCtxT ctx m a -> ActionCtxT () m a
baseHook) forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a
nextHook =
(forall a. ActionCtxT ctx' m a -> ActionCtxT () m a)
-> LiftHooked ctx' m
forall ctx (m :: * -> *).
(forall a. ActionCtxT ctx m a -> ActionCtxT () m a)
-> LiftHooked ctx m
LiftHooked ((forall a. ActionCtxT ctx' m a -> ActionCtxT () m a)
-> LiftHooked ctx' m)
-> (forall a. ActionCtxT ctx' m a -> ActionCtxT () m a)
-> LiftHooked ctx' m
forall a b. (a -> b) -> a -> b
$ ActionCtxT ctx m a -> ActionCtxT () m a
forall a. ActionCtxT ctx m a -> ActionCtxT () m a
baseHook (ActionCtxT ctx m a -> ActionCtxT () m a)
-> (ActionCtxT ctx' m a -> ActionCtxT ctx m a)
-> ActionCtxT ctx' m a
-> ActionCtxT () m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ActionCtxT ctx' m a -> ActionCtxT ctx m a
forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a
nextHook
newtype SpockCtxT ctx m a = SpockCtxT
{ forall ctx (m :: * -> *) a.
SpockCtxT ctx m a -> SpockAllT m (ReaderT (LiftHooked ctx m) m) a
runSpockT :: W.SpockAllT m (ReaderT (LiftHooked ctx m) m) a
}
deriving (Applicative (SpockCtxT ctx m)
Applicative (SpockCtxT ctx m) =>
(forall a b.
SpockCtxT ctx m a -> (a -> SpockCtxT ctx m b) -> SpockCtxT ctx m b)
-> (forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b)
-> (forall a. a -> SpockCtxT ctx m a)
-> Monad (SpockCtxT ctx m)
forall a. a -> SpockCtxT ctx m a
forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
forall a b.
SpockCtxT ctx m a -> (a -> SpockCtxT ctx m b) -> SpockCtxT ctx m b
forall ctx (m :: * -> *). Monad m => Applicative (SpockCtxT ctx m)
forall ctx (m :: * -> *) a. Monad m => a -> SpockCtxT ctx m a
forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> (a -> SpockCtxT ctx m b) -> SpockCtxT ctx m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> (a -> SpockCtxT ctx m b) -> SpockCtxT ctx m b
>>= :: forall a b.
SpockCtxT ctx m a -> (a -> SpockCtxT ctx m b) -> SpockCtxT ctx m b
$c>> :: forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
>> :: forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
$creturn :: forall ctx (m :: * -> *) a. Monad m => a -> SpockCtxT ctx m a
return :: forall a. a -> SpockCtxT ctx m a
Monad, (forall a b. (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b)
-> (forall a b. a -> SpockCtxT ctx m b -> SpockCtxT ctx m a)
-> Functor (SpockCtxT ctx m)
forall a b. a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
forall a b. (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
forall ctx (m :: * -> *) a b.
Functor m =>
a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
forall ctx (m :: * -> *) a b.
Functor m =>
(a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall ctx (m :: * -> *) a b.
Functor m =>
(a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
fmap :: forall a b. (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
$c<$ :: forall ctx (m :: * -> *) a b.
Functor m =>
a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
<$ :: forall a b. a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
Functor, Functor (SpockCtxT ctx m)
Functor (SpockCtxT ctx m) =>
(forall a. a -> SpockCtxT ctx m a)
-> (forall a b.
SpockCtxT ctx m (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b)
-> (forall a b c.
(a -> b -> c)
-> SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m c)
-> (forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b)
-> (forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m a)
-> Applicative (SpockCtxT ctx m)
forall a. a -> SpockCtxT ctx m a
forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
forall a b.
SpockCtxT ctx m (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
forall a b c.
(a -> b -> c)
-> SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m c
forall ctx (m :: * -> *). Monad m => Functor (SpockCtxT ctx m)
forall ctx (m :: * -> *) a. Monad m => a -> SpockCtxT ctx m a
forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
forall ctx (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall ctx (m :: * -> *) a. Monad m => a -> SpockCtxT ctx m a
pure :: forall a. a -> SpockCtxT ctx m a
$c<*> :: forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
<*> :: forall a b.
SpockCtxT ctx m (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b
$cliftA2 :: forall ctx (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m c
liftA2 :: forall a b c.
(a -> b -> c)
-> SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m c
$c*> :: forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
*> :: forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b
$c<* :: forall ctx (m :: * -> *) a b.
Monad m =>
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
<* :: forall a b.
SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m a
Applicative, Monad (SpockCtxT ctx m)
Monad (SpockCtxT ctx m) =>
(forall a. IO a -> SpockCtxT ctx m a) -> MonadIO (SpockCtxT ctx m)
forall a. IO a -> SpockCtxT ctx m a
forall ctx (m :: * -> *). MonadIO m => Monad (SpockCtxT ctx m)
forall ctx (m :: * -> *) a. MonadIO m => IO a -> SpockCtxT ctx m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
$cliftIO :: forall ctx (m :: * -> *) a. MonadIO m => IO a -> SpockCtxT ctx m a
liftIO :: forall a. IO a -> SpockCtxT ctx m a
MonadIO)
instance MonadTrans (SpockCtxT ctx) where
lift :: forall (m :: * -> *) a. Monad m => m a -> SpockCtxT ctx m a
lift = SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a
forall ctx (m :: * -> *) a.
SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a
SpockCtxT (SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a)
-> (m a -> SpockAllT m (ReaderT (LiftHooked ctx m) m) a)
-> m a
-> SpockCtxT ctx m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT (LiftHooked ctx m) m a
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) a
forall (m :: * -> *) a.
Monad m =>
m a -> RegistryT (ActionT m) () Middleware SpockMethod m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT (LiftHooked ctx m) m a
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) a)
-> (m a -> ReaderT (LiftHooked ctx m) m a)
-> m a
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> ReaderT (LiftHooked ctx m) m a
forall (m :: * -> *) a.
Monad m =>
m a -> ReaderT (LiftHooked ctx m) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
instance RouteM SpockCtxT where
addMiddleware :: forall (m :: * -> *) ctx.
Monad m =>
Middleware -> SpockCtxT ctx m ()
addMiddleware = SpockAllT m (ReaderT (LiftHooked ctx m) m) () -> SpockCtxT ctx m ()
forall ctx (m :: * -> *) a.
SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a
SpockCtxT (SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ())
-> (Middleware -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> Middleware
-> SpockCtxT ctx m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Middleware -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) middleware (n :: * -> *) b reqTypes.
Monad m =>
middleware -> RegistryT n b middleware reqTypes m ()
AR.middleware
wireAny :: forall (m :: * -> *) ctx.
Monad m =>
SpockMethod
-> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
wireAny SpockMethod
m [Text] -> ActionCtxT ctx m ()
action =
SpockAllT m (ReaderT (LiftHooked ctx m) m) () -> SpockCtxT ctx m ()
forall ctx (m :: * -> *) a.
SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a
SpockCtxT (SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ()
forall a b. (a -> b) -> a -> b
$
do
hookLift <- ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(ActionCtxT ctx m () -> ActionCtxT () m ())
forall (m :: * -> *) a.
Monad m =>
m a -> RegistryT (ActionT m) () Middleware SpockMethod m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(ActionCtxT ctx m () -> ActionCtxT () m ()))
-> ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(ActionCtxT ctx m () -> ActionCtxT () m ())
forall a b. (a -> b) -> a -> b
$ (LiftHooked ctx m -> ActionCtxT ctx m () -> ActionCtxT () m ())
-> ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (\LiftHooked ctx m
x -> LiftHooked ctx m
-> forall a. ActionCtxT ctx m a -> ActionCtxT () m a
forall ctx (m :: * -> *).
LiftHooked ctx m
-> forall a. ActionCtxT ctx m a -> ActionCtxT () m a
unLiftHooked LiftHooked ctx m
x)
case m of
SpockMethod
MethodAny ->
do
[SpockMethod]
-> (SpockMethod -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SpockMethod]
allStdMethods ((SpockMethod -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> (SpockMethod -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall a b. (a -> b) -> a -> b
$ \SpockMethod
mReg ->
SpockMethod
-> ([Text] -> ActionCtxT () m ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) reqTypes (n :: * -> *) b middleware.
(Monad m, Eq reqTypes, Hashable reqTypes) =>
reqTypes
-> ([Text] -> n b) -> RegistryT n b middleware reqTypes m ()
AR.hookAny SpockMethod
mReg (ActionCtxT ctx m () -> ActionCtxT () m ()
hookLift (ActionCtxT ctx m () -> ActionCtxT () m ())
-> ([Text] -> ActionCtxT ctx m ()) -> [Text] -> ActionCtxT () m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> ActionCtxT ctx m ()
action)
([Text] -> ActionCtxT () m ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) (n :: * -> *) b middleware reqTypes.
Monad m =>
([Text] -> n b) -> RegistryT n b middleware reqTypes m ()
AR.hookAnyMethod (ActionCtxT ctx m () -> ActionCtxT () m ()
hookLift (ActionCtxT ctx m () -> ActionCtxT () m ())
-> ([Text] -> ActionCtxT ctx m ()) -> [Text] -> ActionCtxT () m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> ActionCtxT ctx m ()
action)
SpockMethod
_ -> SpockMethod
-> ([Text] -> ActionCtxT () m ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) reqTypes (n :: * -> *) b middleware.
(Monad m, Eq reqTypes, Hashable reqTypes) =>
reqTypes
-> ([Text] -> n b) -> RegistryT n b middleware reqTypes m ()
AR.hookAny SpockMethod
m (ActionCtxT ctx m () -> ActionCtxT () m ()
hookLift (ActionCtxT ctx m () -> ActionCtxT () m ())
-> ([Text] -> ActionCtxT ctx m ()) -> [Text] -> ActionCtxT () m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> ActionCtxT ctx m ()
action)
withPrehook :: forall (m :: * -> *) ctx ctx'.
MonadIO m =>
ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
withPrehook = ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
forall (m :: * -> *) ctx ctx'.
MonadIO m =>
ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
withPrehookImpl
wireRoute :: forall (m :: * -> *) (xs :: [*]) (ps :: PathState) ctx.
(Monad m, HasRep xs) =>
SpockMethod
-> Path xs ps
-> HVectElim xs (ActionCtxT ctx m ())
-> SpockCtxT ctx m ()
wireRoute = SpockMethod
-> Path xs ps
-> HVectElim xs (ActionCtxT ctx m ())
-> SpockCtxT ctx m ()
forall (xs :: [*]) ctx (m :: * -> *) (ps :: PathState).
(HasRep xs, Monad m) =>
SpockMethod
-> Path xs ps
-> HVectElim xs (ActionCtxT ctx m ())
-> SpockCtxT ctx m ()
wireRouteImpl
withPrehookImpl :: forall m ctx ctx'. MonadIO m => ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
withPrehookImpl :: forall (m :: * -> *) ctx ctx'.
MonadIO m =>
ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
withPrehookImpl ActionCtxT ctx m ctx'
hook (SpockCtxT SpockAllT m (ReaderT (LiftHooked ctx' m) m) ()
hookBody) =
SpockAllT m (ReaderT (LiftHooked ctx m) m) () -> SpockCtxT ctx m ()
forall ctx (m :: * -> *) a.
SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a
SpockCtxT (SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ()
forall a b. (a -> b) -> a -> b
$
do
prevHook <- ReaderT (LiftHooked ctx m) m (LiftHooked ctx m)
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(LiftHooked ctx m)
forall (m :: * -> *) a.
Monad m =>
m a -> RegistryT (ActionT m) () Middleware SpockMethod m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT (LiftHooked ctx m) m (LiftHooked ctx m)
forall r (m :: * -> *). MonadReader r m => m r
ask
let newHook :: ActionCtxT ctx' m a -> ActionCtxT ctx m a
newHook ActionCtxT ctx' m a
act =
do
newCtx <- ActionCtxT ctx m ctx'
hook
runInContext newCtx act
hookLift :: forall a. ReaderT (LiftHooked ctx' m) m a -> ReaderT (LiftHooked ctx m) m a
hookLift ReaderT (LiftHooked ctx' m) m a
a =
m a -> ReaderT (LiftHooked ctx m) m a
forall (m :: * -> *) a.
Monad m =>
m a -> ReaderT (LiftHooked ctx m) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT (LiftHooked ctx m) m a)
-> m a -> ReaderT (LiftHooked ctx m) m a
forall a b. (a -> b) -> a -> b
$ ReaderT (LiftHooked ctx' m) m a -> LiftHooked ctx' m -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT (LiftHooked ctx' m) m a
a (LiftHooked ctx m
-> (forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a)
-> LiftHooked ctx' m
forall ctx (m :: * -> *) ctx'.
LiftHooked ctx m
-> (forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a)
-> LiftHooked ctx' m
injectHook LiftHooked ctx m
prevHook ActionCtxT ctx' m a -> ActionCtxT ctx m a
forall a. ActionCtxT ctx' m a -> ActionCtxT ctx m a
newHook)
swapMonad hookLift hookBody
wireRouteImpl :: forall xs ctx m ps. (HasRep xs, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
wireRouteImpl :: forall (xs :: [*]) ctx (m :: * -> *) (ps :: PathState).
(HasRep xs, Monad m) =>
SpockMethod
-> Path xs ps
-> HVectElim xs (ActionCtxT ctx m ())
-> SpockCtxT ctx m ()
wireRouteImpl SpockMethod
m Path xs ps
path HVectElim xs (ActionCtxT ctx m ())
action =
SpockAllT m (ReaderT (LiftHooked ctx m) m) () -> SpockCtxT ctx m ()
forall ctx (m :: * -> *) a.
SpockAllT m (ReaderT (LiftHooked ctx m) m) a -> SpockCtxT ctx m a
SpockCtxT (SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
-> SpockCtxT ctx m ()
forall a b. (a -> b) -> a -> b
$
do
hookLift <- ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(ActionCtxT ctx m () -> ActionCtxT () m ())
forall (m :: * -> *) a.
Monad m =>
m a -> RegistryT (ActionT m) () Middleware SpockMethod m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(ActionCtxT ctx m () -> ActionCtxT () m ()))
-> ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked ctx m) m)
(ActionCtxT ctx m () -> ActionCtxT () m ())
forall a b. (a -> b) -> a -> b
$ (LiftHooked ctx m -> ActionCtxT ctx m () -> ActionCtxT () m ())
-> ReaderT
(LiftHooked ctx m) m (ActionCtxT ctx m () -> ActionCtxT () m ())
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (\LiftHooked ctx m
x -> LiftHooked ctx m
-> forall a. ActionCtxT ctx m a -> ActionCtxT () m a
forall ctx (m :: * -> *).
LiftHooked ctx m
-> forall a. ActionCtxT ctx m a -> ActionCtxT () m a
unLiftHooked LiftHooked ctx m
x)
let actionPacker :: HVectElim xs (ActionCtxT ctx m ()) -> HVect xs -> ActionCtxT () m ()
actionPacker HVectElim xs (ActionCtxT ctx m ())
act HVect xs
captures = ActionCtxT ctx m () -> ActionCtxT () m ()
hookLift (HVectElim xs (ActionCtxT ctx m ())
-> HVect xs -> ActionCtxT ctx m ()
forall (ts :: [*]) a. HVectElim ts a -> HVect ts -> a
uncurry HVectElim xs (ActionCtxT ctx m ())
act HVect xs
captures)
case m of
SpockMethod
MethodAny ->
do
[SpockMethod]
-> (SpockMethod -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [SpockMethod]
allStdMethods ((SpockMethod -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> (SpockMethod -> SpockAllT m (ReaderT (LiftHooked ctx m) m) ())
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall a b. (a -> b) -> a -> b
$ \SpockMethod
mReg ->
SpockMethod
-> PathInternal xs
-> HVectElim' (ActionCtxT () m ()) xs
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) reqTypes (as :: [*]) (n :: * -> *) b
middleware.
(Monad m, Eq reqTypes, Hashable reqTypes) =>
reqTypes
-> PathInternal as
-> HVectElim' (n b) as
-> RegistryT n b middleware reqTypes m ()
AR.hookRoute SpockMethod
mReg (Path xs ps -> PathInternal xs
forall (as :: [*]) (pathState :: PathState).
Path as pathState -> PathInternal as
toInternalPath Path xs ps
path) (HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs
forall x (ts :: [*]). HVectElim ts x -> HVectElim' x ts
HVectElim' (HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs)
-> HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs
forall a b. (a -> b) -> a -> b
$ (HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ())
forall (ts :: [*]) a.
HasRep ts =>
(HVect ts -> a) -> HVectElim ts a
curry ((HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ()))
-> (HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ())
forall a b. (a -> b) -> a -> b
$ HVectElim xs (ActionCtxT ctx m ())
-> HVect xs -> ActionCtxT () m ()
actionPacker HVectElim xs (ActionCtxT ctx m ())
action)
PathInternal xs
-> HVectElim' (ActionCtxT () m ()) xs
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) (as :: [*]) (n :: * -> *) b middleware
reqTypes.
Monad m =>
PathInternal as
-> HVectElim' (n b) as -> RegistryT n b middleware reqTypes m ()
AR.hookRouteAnyMethod (Path xs ps -> PathInternal xs
forall (as :: [*]) (pathState :: PathState).
Path as pathState -> PathInternal as
toInternalPath Path xs ps
path) (HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs
forall x (ts :: [*]). HVectElim ts x -> HVectElim' x ts
HVectElim' (HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs)
-> HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs
forall a b. (a -> b) -> a -> b
$ (HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ())
forall (ts :: [*]) a.
HasRep ts =>
(HVect ts -> a) -> HVectElim ts a
curry ((HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ()))
-> (HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ())
forall a b. (a -> b) -> a -> b
$ HVectElim xs (ActionCtxT ctx m ())
-> HVect xs -> ActionCtxT () m ()
actionPacker HVectElim xs (ActionCtxT ctx m ())
action)
SpockMethod
_ -> SpockMethod
-> PathInternal xs
-> HVectElim' (ActionCtxT () m ()) xs
-> SpockAllT m (ReaderT (LiftHooked ctx m) m) ()
forall (m :: * -> *) reqTypes (as :: [*]) (n :: * -> *) b
middleware.
(Monad m, Eq reqTypes, Hashable reqTypes) =>
reqTypes
-> PathInternal as
-> HVectElim' (n b) as
-> RegistryT n b middleware reqTypes m ()
AR.hookRoute SpockMethod
m (Path xs ps -> PathInternal xs
forall (as :: [*]) (pathState :: PathState).
Path as pathState -> PathInternal as
toInternalPath Path xs ps
path) (HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs
forall x (ts :: [*]). HVectElim ts x -> HVectElim' x ts
HVectElim' (HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs)
-> HVectElim xs (ActionCtxT () m ())
-> HVectElim' (ActionCtxT () m ()) xs
forall a b. (a -> b) -> a -> b
$ (HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ())
forall (ts :: [*]) a.
HasRep ts =>
(HVect ts -> a) -> HVectElim ts a
curry ((HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ()))
-> (HVect xs -> ActionCtxT () m ())
-> HVectElim xs (ActionCtxT () m ())
forall a b. (a -> b) -> a -> b
$ HVectElim xs (ActionCtxT ctx m ())
-> HVect xs -> ActionCtxT () m ()
actionPacker HVectElim xs (ActionCtxT ctx m ())
action)
allStdMethods :: [SpockMethod]
allStdMethods :: [SpockMethod]
allStdMethods = HttpMethod -> SpockMethod
MethodStandard (HttpMethod -> SpockMethod) -> [HttpMethod] -> [SpockMethod]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HttpMethod
forall a. Bounded a => a
minBound .. HttpMethod
forall a. Bounded a => a
maxBound]
runSpock :: Warp.Port -> IO Wai.Middleware -> IO ()
runSpock :: Int -> IO Middleware -> IO ()
runSpock Int
port IO Middleware
mw =
do
Handle -> [Char] -> IO ()
hPutStrLn Handle
stderr ([Char]
"Spock is running on port " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
port)
app <- IO Middleware -> IO Application
spockAsApp IO Middleware
mw
Warp.run port app
runSpockNoBanner :: Warp.Port -> IO Wai.Middleware -> IO ()
runSpockNoBanner :: Int -> IO Middleware -> IO ()
runSpockNoBanner Int
port IO Middleware
mw =
do
app <- IO Middleware -> IO Application
spockAsApp IO Middleware
mw
Warp.run port app
spockAsApp :: IO Wai.Middleware -> IO Wai.Application
spockAsApp :: IO Middleware -> IO Application
spockAsApp = (Middleware -> Application) -> IO Middleware -> IO Application
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Middleware -> Application
W.middlewareToApp
spockT ::
(MonadIO m) =>
(forall a. m a -> IO a) ->
SpockT m () ->
IO Wai.Middleware
spockT :: forall (m :: * -> *).
MonadIO m =>
(forall a. m a -> IO a) -> SpockT m () -> IO Middleware
spockT = SpockConfig
-> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
forall (m :: * -> *).
MonadIO m =>
SpockConfig
-> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
spockConfigT SpockConfig
defaultSpockConfig
spockConfigT ::
forall m.
MonadIO m =>
SpockConfig ->
(forall a. m a -> IO a) ->
SpockT m () ->
IO Wai.Middleware
spockConfigT :: forall (m :: * -> *).
MonadIO m =>
SpockConfig
-> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
spockConfigT SpockConfig
cfg forall a. m a -> IO a
liftFun SpockT m ()
app = do
logger <- (LoggingConfig -> IO RequestLogger)
-> Maybe LoggingConfig -> IO (Maybe RequestLogger)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse LoggingConfig -> IO RequestLogger
newRequestLogger (SpockConfig -> Maybe LoggingConfig
sc_logging SpockConfig
cfg)
let internalConfig = Maybe Word64
-> (Status -> IO Application)
-> (Text -> IO ())
-> Maybe RequestLogger
-> SlashPolicy
-> SpockConfigInternal
W.SpockConfigInternal (SpockConfig -> Maybe Word64
sc_maxRequestSize SpockConfig
cfg) (Maybe RequestLogger -> Status -> IO Application
errorHandler Maybe RequestLogger
logger) (SpockConfig -> Text -> IO ()
sc_logError SpockConfig
cfg) Maybe RequestLogger
logger (SpockConfig -> SlashPolicy
sc_slashPolicy SpockConfig
cfg)
W.buildMiddleware internalConfig liftFun (baseAppHook app)
where
errorHandler :: Maybe RequestLogger -> Status -> IO Application
errorHandler Maybe RequestLogger
logger Status
status = IO Middleware -> IO Application
spockAsApp (IO Middleware -> IO Application)
-> IO Middleware -> IO Application
forall a b. (a -> b) -> a -> b
$ SpockConfigInternal
-> (forall a. IO a -> IO a) -> SpockAllT IO IO () -> IO Middleware
forall (m :: * -> *).
MonadIO m =>
SpockConfigInternal
-> (forall a. m a -> IO a) -> SpockAllT m m () -> IO Middleware
W.buildMiddleware
(SpockConfigInternal
W.defaultSpockConfigInternal { W.sci_requestLogger = logger }) IO a -> IO a
forall a. a -> a
forall a. IO a -> IO a
id (SpockAllT IO IO () -> IO Middleware)
-> SpockAllT IO IO () -> IO Middleware
forall a b. (a -> b) -> a -> b
$ SpockT IO () -> SpockAllT IO IO ()
forall (m :: * -> *). MonadIO m => SpockT m () -> SpockAllT m m ()
baseAppHook (SpockT IO () -> SpockAllT IO IO ())
-> SpockT IO () -> SpockAllT IO IO ()
forall a b. (a -> b) -> a -> b
$ Status -> SpockT IO ()
errorApp Status
status
errorApp :: Status -> SpockT IO ()
errorApp Status
status = (StdMethod -> SpockT IO ()) -> [StdMethod] -> SpockT IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\StdMethod
method -> StdMethod -> ([Text] -> ActionCtxT () IO ()) -> SpockT IO ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny StdMethod
method (([Text] -> ActionCtxT () IO ()) -> SpockT IO ())
-> ([Text] -> ActionCtxT () IO ()) -> SpockT IO ()
forall a b. (a -> b) -> a -> b
$ \[Text]
_ -> Status -> ActionCtxT () IO ()
errorAction' Status
status) [StdMethod
forall a. Bounded a => a
minBound .. StdMethod
forall a. Bounded a => a
maxBound]
errorAction' :: Status -> ActionCtxT () IO ()
errorAction' Status
status = Status -> ActionCtxT () IO ()
forall (m :: * -> *) ctx.
MonadIO m =>
Status -> ActionCtxT ctx m ()
setStatus Status
status ActionCtxT () IO () -> ActionCtxT () IO () -> ActionCtxT () IO ()
forall a b.
ActionCtxT () IO a -> ActionCtxT () IO b -> ActionCtxT () IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SpockConfig -> Status -> ActionCtxT () IO ()
sc_errorHandler SpockConfig
cfg Status
status
baseAppHook :: forall m. MonadIO m => SpockT m () -> W.SpockAllT m m ()
baseAppHook :: forall (m :: * -> *). MonadIO m => SpockT m () -> SpockAllT m m ()
baseAppHook SpockT m ()
app =
(forall b. ReaderT (LiftHooked () m) m b -> m b)
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked () m) m)
()
-> RegistryT (ActionT m) () Middleware SpockMethod m ()
forall (m :: * -> *) (n :: * -> *) (x :: * -> *) y middleware
reqTypes a.
Monad m =>
(forall b. n b -> m b)
-> RegistryT x y middleware reqTypes n a
-> RegistryT x y middleware reqTypes m a
swapMonad ReaderT (LiftHooked () m) m b -> m b
forall b. ReaderT (LiftHooked () m) m b -> m b
lifter (SpockT m ()
-> RegistryT
(ActionT m)
()
Middleware
SpockMethod
(ReaderT (LiftHooked () m) m)
()
forall ctx (m :: * -> *) a.
SpockCtxT ctx m a -> SpockAllT m (ReaderT (LiftHooked ctx m) m) a
runSpockT SpockT m ()
app)
where
lifter :: forall b. ReaderT (LiftHooked () m) m b -> m b
lifter :: forall b. ReaderT (LiftHooked () m) m b -> m b
lifter ReaderT (LiftHooked () m) m b
action = ReaderT (LiftHooked () m) m b -> LiftHooked () m -> m b
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT (LiftHooked () m) m b
action ((forall a. ActionCtxT () m a -> ActionCtxT () m a)
-> LiftHooked () m
forall ctx (m :: * -> *).
(forall a. ActionCtxT ctx m a -> ActionCtxT () m a)
-> LiftHooked ctx m
LiftHooked ActionCtxT () m a -> ActionCtxT () m a
forall a. a -> a
forall a. ActionCtxT () m a -> ActionCtxT () m a
id)
get :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
get :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
get = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
GET
post :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
post :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
post = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
POST
getpost :: (HasRep xs, RouteM t, Monad m, Monad (t ctx m)) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
getpost :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx
(ps :: PathState).
(HasRep xs, RouteM t, Monad m, Monad (t ctx m)) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
getpost Path xs ps
r HVectElim xs (ActionCtxT ctx m ())
a = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
POST Path xs ps
r HVectElim xs (ActionCtxT ctx m ())
a t ctx m () -> t ctx m () -> t ctx m ()
forall a b. t ctx m a -> t ctx m b -> t ctx m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
GET Path xs ps
r HVectElim xs (ActionCtxT ctx m ())
a
head :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
head :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
head = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
HEAD
put :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
put :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
put = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
PUT
delete :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
delete :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
delete = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
DELETE
patch :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
patch :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
patch = StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute StdMethod
PATCH
prehook :: (RouteM t, MonadIO m) => ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
prehook :: forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx ctx'.
(RouteM t, MonadIO m) =>
ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
prehook = ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
forall (m :: * -> *) ctx ctx'.
MonadIO m =>
ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx ctx'.
(RouteM t, MonadIO m) =>
ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
withPrehook
hookRoute :: (HasRep xs, RouteM t, Monad m) => StdMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
StdMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute = SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute' (SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ())
-> (StdMethod -> SpockMethod)
-> StdMethod
-> Path xs ps
-> HVectElim xs (ActionCtxT ctx m ())
-> t ctx m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HttpMethod -> SpockMethod
MethodStandard (HttpMethod -> SpockMethod)
-> (StdMethod -> HttpMethod) -> StdMethod -> SpockMethod
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StdMethod -> HttpMethod
W.HttpMethod
hookRouteAll :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRouteAll :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRouteAll = SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute' SpockMethod
MethodAny
hookRouteCustom :: (HasRep xs, RouteM t, Monad m) => T.Text -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRouteCustom :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
Text
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRouteCustom = SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute' (SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ())
-> (Text -> SpockMethod)
-> Text
-> Path xs ps
-> HVectElim xs (ActionCtxT ctx m ())
-> t ctx m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> SpockMethod
MethodCustom
hookRoute' :: (HasRep xs, RouteM t, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute' :: forall (xs :: [*]) (t :: * -> (* -> *) -> * -> *) (m :: * -> *)
(ps :: PathState) ctx.
(HasRep xs, RouteM t, Monad m) =>
SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
hookRoute' = SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (m :: * -> *) (xs :: [*]) (ps :: PathState) ctx.
(Monad m, HasRep xs) =>
SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) (xs :: [*])
(ps :: PathState) ctx.
(RouteM t, Monad m, HasRep xs) =>
SpockMethod
-> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
wireRoute
hookAny :: (RouteM t, Monad m) => StdMethod -> ([T.Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny :: forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny = SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny' (SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ())
-> (StdMethod -> SpockMethod)
-> StdMethod
-> ([Text] -> ActionCtxT ctx m ())
-> t ctx m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HttpMethod -> SpockMethod
MethodStandard (HttpMethod -> SpockMethod)
-> (StdMethod -> HttpMethod) -> StdMethod -> SpockMethod
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StdMethod -> HttpMethod
W.HttpMethod
hookAnyAll :: (RouteM t, Monad m) => ([T.Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAnyAll :: forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAnyAll = SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny' SpockMethod
MethodAny
hookAnyCustom :: (RouteM t, Monad m) => T.Text -> ([T.Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAnyCustom :: forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
Text -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAnyCustom = SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny' (SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ())
-> (Text -> SpockMethod)
-> Text
-> ([Text] -> ActionCtxT ctx m ())
-> t ctx m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> SpockMethod
MethodCustom
hookAny' :: (RouteM t, Monad m) => SpockMethod -> ([T.Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny' :: forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
hookAny' = SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
forall (m :: * -> *) ctx.
Monad m =>
SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
wireAny
middleware :: (RouteM t, Monad m) => Wai.Middleware -> t ctx m ()
middleware :: forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
Middleware -> t ctx m ()
middleware = Middleware -> t ctx m ()
forall (m :: * -> *) ctx. Monad m => Middleware -> t ctx m ()
forall (t :: * -> (* -> *) -> * -> *) (m :: * -> *) ctx.
(RouteM t, Monad m) =>
Middleware -> t ctx m ()
addMiddleware
(<//>) :: Path as 'Open -> Path bs ps -> Path (Append as bs) ps
<//> :: forall (as :: [*]) (bs :: [*]) (ps :: PathState).
Path as 'Open -> Path bs ps -> Path (Append as bs) ps
(<//>) = Path as 'Open -> Path bs ps -> Path (Append as bs) ps
forall (as :: [*]) (bs :: [*]) (ps :: PathState).
Path as 'Open -> Path bs ps -> Path (Append as bs) ps
(</>)
renderRoute :: AllHave ToHttpApiData as => Path as 'Open -> HVectElim as T.Text
renderRoute :: forall (as :: [*]).
AllHave ToHttpApiData as =>
Path as 'Open -> HVectElim as Text
renderRoute = SlashPolicy -> Path as 'Open -> HVectElim as Text
forall (as :: [*]).
AllHave ToHttpApiData as =>
SlashPolicy -> Path as 'Open -> HVectElim as Text
renderRouteWith SlashPolicy
IgnoreSlashes
renderRouteWith :: AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as T.Text
renderRouteWith :: forall (as :: [*]).
AllHave ToHttpApiData as =>
SlashPolicy -> Path as 'Open -> HVectElim as Text
renderRouteWith SlashPolicy
policy Path as 'Open
route = Rep as -> (HVect as -> Text) -> HVectElim as Text
forall (ts :: [*]) a. Rep ts -> (HVect ts -> a) -> HVectElim ts a
curryExpl (Path as 'Open -> Rep as
forall (as :: [*]) (ps :: PathState). Path as ps -> Rep as
pathToRep Path as 'Open
route) (Char -> Text -> Text
T.cons Char
'/' (Text -> Text) -> (HVect as -> Text) -> HVect as -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SlashPolicy -> Path as 'Open -> HVect as -> Text
forall (as :: [*]).
AllHave ToHttpApiData as =>
SlashPolicy -> Path as 'Open -> HVect as -> Text
COMB.renderRouteWith SlashPolicy
policy Path as 'Open
route)
renderRouteEncoded :: AllHave ToHttpApiData as => Path as 'Open -> HVectElim as T.Text
renderRouteEncoded :: forall (as :: [*]).
AllHave ToHttpApiData as =>
Path as 'Open -> HVectElim as Text
renderRouteEncoded = SlashPolicy -> Path as 'Open -> HVectElim as Text
forall (as :: [*]).
AllHave ToHttpApiData as =>
SlashPolicy -> Path as 'Open -> HVectElim as Text
renderRouteEncodedWith SlashPolicy
IgnoreSlashes
renderRouteEncodedWith :: AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as T.Text
renderRouteEncodedWith :: forall (as :: [*]).
AllHave ToHttpApiData as =>
SlashPolicy -> Path as 'Open -> HVectElim as Text
renderRouteEncodedWith SlashPolicy
policy Path as 'Open
route = Rep as -> (HVect as -> Text) -> HVectElim as Text
forall (ts :: [*]) a. Rep ts -> (HVect ts -> a) -> HVectElim ts a
curryExpl (Path as 'Open -> Rep as
forall (as :: [*]) (ps :: PathState). Path as ps -> Rep as
pathToRep Path as 'Open
route) (Char -> Text -> Text
T.cons Char
'/' (Text -> Text) -> (HVect as -> Text) -> HVect as -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SlashPolicy -> Path as 'Open -> HVect as -> Text
forall (as :: [*]).
AllHave ToHttpApiData as =>
SlashPolicy -> Path as 'Open -> HVect as -> Text
COMB.renderRouteEncodedWith SlashPolicy
policy Path as 'Open
route)