Spock
Safe HaskellNone
LanguageHaskell2010

Web.Spock

Description

Build an application with typed routes, sessions, and a database pool.

Reading requests and sending responses

Request and response helpers are reexported from Web.Spock.Action in the Spock-core package. Follow that module link for the complete action API:

The API reference links the current versions of Spock, Spock-core, the typed API packages, and session adapters.

Synopsis

Launching Spock

runSpock :: Port -> IO Middleware -> IO () #

Run a Spock application using run from Network.Wai.Handler.Warp.

runSpockNoBanner :: Port -> IO Middleware -> IO () #

Like runSpock, but does not display the banner "Spock is running on port XXX" on stdout.

spockAsApp :: IO Middleware -> IO Application #

Convert a middleware to an application. All failing requests will result in a 404 page

Spock's route definition monad

spock :: SpockCfg conn sess st -> SpockM conn sess st () -> IO Middleware Source #

Create a spock application using a given db storageLayer and an initial state. Spock works with database libraries that already implement connection pooling and with those that don't come with it out of the box. For more see the PoolOrConn type. Use runSpock to run the app or spockAsApp to create a Wai.Application

type SpockM conn sess st = SpockCtxM () conn sess st Source #

Register routes and middleware when the application starts. The handler passed to a route runs later, once per matching request, in SpockAction.

conn is a database connection, sess is one visitor's session value, and st is application-wide state. The final result parameter is usually (). This is SpockCtxM with an empty request context. Use SpockCtxM inside a prehook that supplies a typed context.

type SpockCtxM ctx conn sess st = SpockCtxT ctx (WebStateM conn sess st) Source #

Route registration with handlers that receive context ctx. A prehook produces this context per request; getContext reads it in the handler. Context belongs to the selected request and hook scope, while st is shared by the entire application and sess belongs to a visitor's session.

The underlying monad is WebStateM: lift helper runs a shared-state or database helper during registration. Inside a handler, the same expression runs it for that request. Use liftIO for an ordinary IO operation.

Defining routes

data Path (as :: [Type]) (pathState :: PathState) #

Instances

Instances details
(a ~ ('[] :: [Type]), pathState ~ 'Open) => IsString (Path a pathState)  
Instance details

Defined in Web.Routing.Combinators

Methods

fromString :: String -> Path a pathState

root :: Path ('[] :: [Type]) 'Open #

The root of a path piece. Use to define a handler for "/"

type Var a = Path '[a] 'Open #

data AltVar a b #

A variant of Either with a FromHttpApiData definition that tries both branches without a prefix. Useful to define routes with vars that should work with different types.

Constructors

AvLeft a 
AvRight b 

Instances

Instances details
(Eq a, Eq b) => Eq (AltVar a b)  
Instance details

Defined in Web.Routing.Combinators

Methods

(==) :: AltVar a b -> AltVar a b -> Bool

(/=) :: AltVar a b -> AltVar a b -> Bool

(Ord a, Ord b) => Ord (AltVar a b)  
Instance details

Defined in Web.Routing.Combinators

Methods

compare :: AltVar a b -> AltVar a b -> Ordering

(<) :: AltVar a b -> AltVar a b -> Bool

(<=) :: AltVar a b -> AltVar a b -> Bool

(>) :: AltVar a b -> AltVar a b -> Bool

(>=) :: AltVar a b -> AltVar a b -> Bool

max :: AltVar a b -> AltVar a b -> AltVar a b

min :: AltVar a b -> AltVar a b -> AltVar a b

(Read a, Read b) => Read (AltVar a b)  
Instance details

Defined in Web.Routing.Combinators

Methods

readsPrec :: Int -> ReadS (AltVar a b)

readList :: ReadS [AltVar a b]

readPrec :: ReadPrec (AltVar a b)

readListPrec :: ReadPrec [AltVar a b]

(Show a, Show b) => Show (AltVar a b)  
Instance details

Defined in Web.Routing.Combinators

Methods

showsPrec :: Int -> AltVar a b -> ShowS

show :: AltVar a b -> String

showList :: [AltVar a b] -> ShowS

(FromHttpApiData a, FromHttpApiData b) => FromHttpApiData (AltVar a b)  
Instance details

Defined in Web.Routing.Combinators

Methods

parseUrlPiece :: Text -> Either Text (AltVar a b)

parseHeader :: ByteString -> Either Text (AltVar a b)

parseQueryParam :: Text -> Either Text (AltVar a b)

var :: (Typeable a, FromHttpApiData a) => Path '[a] 'Open #

A route parameter

static :: String -> Path ('[] :: [Type]) 'Open #

A static route piece. One leading slash is optional. Empty internal and trailing pieces are retained for strict routing; compatibility routing and renderRoute ignore them. Use renderRouteWith with the application's policy.

trailingSlash :: forall (as :: [Type]). Path as 'Open -> Path as 'Open #

Require a trailing slash in strict routing, including after a capture. Root remains root, and a path already ending in a slash is unchanged.

(<//>) :: forall (as :: [Type]) (bs :: [Type]) (ps :: PathState). Path as 'Open -> Path bs ps -> Path (Append as bs) ps #

Combine two path components

(<.>) :: forall (as :: [Type]) (bs :: [Type]). Path as 'Open -> Path bs 'Open -> Path (Append as bs) 'Open infixl 8 #

Join the last segment on the left and the first on the right with a dot. Both sides may contain typed captures: var . "txt" or var . var. Matching tries the rightmost dot first and accepts the first split whose typed parsers and literals succeed. Use a custom capture type to restrict extensions; a Text capture accepts any text, including an empty extension. Static routes take precedence over extensions, then plain captures and wildcards. More literal characters give an extension pattern priority.

wildcard :: Path '[Text] 'Closed #

Matches the rest of the route. Should be the last part of the path.

Rendering routes

renderRoute :: forall (as :: [Type]). AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text #

Render a route applying path pieces

renderRouteWith :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as Text #

Render with the application's slash policy. Use StrictSlashes or RedirectTrailingSlashes to preserve trailing and repeated literal slashes.

renderRouteEncoded :: forall (as :: [Type]). AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text #

Render a URL with each complete path segment percent-encoded.

renderRouteEncodedWith :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as Text #

Percent-encoded rendering with the application's slash policy.

Hooking routes

prehook :: forall t (m :: Type -> Type) ctx ctx'. (RouteM t, MonadIO m) => ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m () #

Specify an action that will be run before all subroutes. It can modify the requests current context

type RouteSpec (t :: Type -> (Type -> Type) -> Type -> Type) (xs :: [Type]) (ps :: PathState) ctx conn sess st = Path xs ps -> HVectElim xs (SpockActionCtx ctx conn sess st ()) -> RouteMonad t ctx conn sess st () Source #

get :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb GET and the given route match

post :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb POST and the given route match

getpost :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb GET/POST and the given route match

head :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb HEAD and the given route match

put :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb PUT and the given route match

delete :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb DELETE and the given route match

patch :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when the HTTP verb PATCH and the given route match

hookRoute :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => StdMethod -> RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when a standard HTTP verb and the given route match

hookRouteCustom :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => Text -> RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run when a custom HTTP verb and the given route match

hookAny :: StdMethod -> ([Text] -> SpockActionCtx ctx conn sess st ()) -> RouteMonad t ctx conn sess st () Source #

Specify an action that will be run when a standard HTTP verb matches but no defined route matches. The full path is passed as an argument

hookAnyCustom :: Text -> ([Text] -> SpockActionCtx ctx conn sess st ()) -> RouteMonad t ctx conn sess st () Source #

Specify an action that will be run when a custom HTTP verb matches but no defined route matches. The full path is passed as an argument

hookRouteAll :: forall (xs :: [Type]) t (ps :: PathState) ctx conn sess st. HasRep xs => RouteSpec t xs ps ctx conn sess st Source #

Specify an action that will be run regardless of the HTTP verb

hookAnyAll :: ([Text] -> SpockActionCtx ctx conn sess st ()) -> RouteMonad t ctx conn sess st () Source #

Specify an action that will be run regardless of the HTTP verb and no defined route matches. The full path is passed as an argument

data StdMethod #

HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).

Since: http-types-0.2.0

Constructors

GET 
POST 
HEAD 
PUT 
DELETE 
TRACE 
CONNECT 
OPTIONS 
PATCH

Since: http-types-0.8.0

Instances

Instances details
Eq StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

(==) :: StdMethod -> StdMethod -> Bool

(/=) :: StdMethod -> StdMethod -> Bool

Ord StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

compare :: StdMethod -> StdMethod -> Ordering

(<) :: StdMethod -> StdMethod -> Bool

(<=) :: StdMethod -> StdMethod -> Bool

(>) :: StdMethod -> StdMethod -> Bool

(>=) :: StdMethod -> StdMethod -> Bool

max :: StdMethod -> StdMethod -> StdMethod

min :: StdMethod -> StdMethod -> StdMethod

Data StdMethod

Since: http-types-0.12.4

Instance details

Defined in Network.HTTP.Types.Method

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> StdMethod -> c StdMethod

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c StdMethod

toConstr :: StdMethod -> Constr

dataTypeOf :: StdMethod -> DataType

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c StdMethod)

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StdMethod)

gmapT :: (forall b. Data b => b -> b) -> StdMethod -> StdMethod

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> StdMethod -> r

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> StdMethod -> r

gmapQ :: (forall d. Data d => d -> u) -> StdMethod -> [u]

gmapQi :: Int -> (forall d. Data d => d -> u) -> StdMethod -> u

gmapM :: Monad m => (forall d. Data d => d -> m d) -> StdMethod -> m StdMethod

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> StdMethod -> m StdMethod

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> StdMethod -> m StdMethod

Bounded StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

minBound :: StdMethod

maxBound :: StdMethod

Enum StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

succ :: StdMethod -> StdMethod

pred :: StdMethod -> StdMethod

toEnum :: Int -> StdMethod

fromEnum :: StdMethod -> Int

enumFrom :: StdMethod -> [StdMethod]

enumFromThen :: StdMethod -> StdMethod -> [StdMethod]

enumFromTo :: StdMethod -> StdMethod -> [StdMethod]

enumFromThenTo :: StdMethod -> StdMethod -> StdMethod -> [StdMethod]

Generic StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Associated Types

type Rep StdMethod

Since: http-types-0.12.4

Instance details

Defined in Network.HTTP.Types.Method

type Rep StdMethod = D1 ('MetaData "StdMethod" "Network.HTTP.Types.Method" "http-typs-0.12.6-c4f7c903" 'False) (((C1 ('MetaCons "GET" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "POST" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HEAD" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PUT" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "DELETE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TRACE" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CONNECT" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OPTIONS" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PATCH" 'PrefixI 'False) (U1 :: Type -> Type)))))

Methods

from :: StdMethod -> Rep StdMethod x

to :: Rep StdMethod x -> StdMethod

Ix StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

range :: (StdMethod, StdMethod) -> [StdMethod]

index :: (StdMethod, StdMethod) -> StdMethod -> Int

unsafeIndex :: (StdMethod, StdMethod) -> StdMethod -> Int

inRange :: (StdMethod, StdMethod) -> StdMethod -> Bool

rangeSize :: (StdMethod, StdMethod) -> Int

unsafeRangeSize :: (StdMethod, StdMethod) -> Int

Read StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

readsPrec :: Int -> ReadS StdMethod

readList :: ReadS [StdMethod]

readPrec :: ReadPrec StdMethod

readListPrec :: ReadPrec [StdMethod]

Show StdMethod  
Instance details

Defined in Network.HTTP.Types.Method

Methods

showsPrec :: Int -> StdMethod -> ShowS

show :: StdMethod -> String

showList :: [StdMethod] -> ShowS

type Rep StdMethod #

Since: http-types-0.12.4

Instance details

Defined in Network.HTTP.Types.Method

type Rep StdMethod = D1 ('MetaData "StdMethod" "Network.HTTP.Types.Method" "http-typs-0.12.6-c4f7c903" 'False) (((C1 ('MetaCons "GET" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "POST" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HEAD" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PUT" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "DELETE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TRACE" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CONNECT" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OPTIONS" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PATCH" 'PrefixI 'False) (U1 :: Type -> Type)))))

Adding Wai.Middleware

middleware :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => Middleware -> t ctx m () #

Hook wai middleware into Spock

Actions

type SpockAction conn sess st = SpockActionCtx () conn sess st Source #

A per-request SpockActionCtx with context (). This is the usual handler type outside a prehook. Its conn, sess, and st parameters have the same meanings as in the application's route-registration type.

type SpockActionCtx ctx conn sess st = ActionCtxT ctx (WebStateM conn sess st) Source #

A per-request action with typed context ctx, database connection conn, session value sess, and shared application state st. The final type parameter is the action's result. Use getContext for the value supplied by a prehook, getState for shared state, and session actions for this visitor.

This is ActionCtxT over WebStateM. lift helper enters WebStateM; liftIO operation runs IO. Sending a response finishes the action even though response helpers have a polymorphic result type.

class HasSpock (m :: Type -> Type) where Source #

Access application services in WebStateM and Spock's registration/action layers. Helpers polymorphic in this class can use getState and runQuery without committing to either of those layers.

Associated Types

type SpockConn (m :: Type -> Type) Source #

type SpockState (m :: Type -> Type) Source #

type SpockSession (m :: Type -> Type) Source #

Methods

runQuery :: (SpockConn m -> IO a) -> m a Source #

Give you access to a database connectin from the connection pool. The connection is released back to the pool once the function terminates.

getState :: m (SpockState m) Source #

Read the application's state. If you wish to have mutable state, you could use a TVar from the STM packge.

getSessMgr :: m (SpockSessionManager (SpockConn m) (SpockSession m) (SpockState m)) Source #

Get the session manager

getSpockCfg :: m (SpockCfg (SpockConn m) (SpockSession m) (SpockState m)) Source #

Get the Spock configuration

Instances

Instances details
MonadTrans t => HasSpock (t (WebStateM conn sess st)) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

Associated Types

type SpockConn (t (WebStateM conn sess st)) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockConn (t (WebStateM conn sess st)) = conn
type SpockState (t (WebStateM conn sess st)) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockState (t (WebStateM conn sess st)) = st
type SpockSession (t (WebStateM conn sess st)) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockSession (t (WebStateM conn sess st)) = sess

Methods

runQuery :: (SpockConn (t (WebStateM conn sess st)) -> IO a) -> t (WebStateM conn sess st) a Source #

getState :: t (WebStateM conn sess st) (SpockState (t (WebStateM conn sess st))) Source #

getSessMgr :: t (WebStateM conn sess st) (SpockSessionManager (SpockConn (t (WebStateM conn sess st))) (SpockSession (t (WebStateM conn sess st))) (SpockState (t (WebStateM conn sess st)))) Source #

getSpockCfg :: t (WebStateM conn sess st) (SpockCfg (SpockConn (t (WebStateM conn sess st))) (SpockSession (t (WebStateM conn sess st))) (SpockState (t (WebStateM conn sess st)))) Source #

HasSpock (WebStateM conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

Associated Types

type SpockConn (WebStateM conn sess st) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockConn (WebStateM conn sess st) = conn
type SpockState (WebStateM conn sess st) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockState (WebStateM conn sess st) = st
type SpockSession (WebStateM conn sess st) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockSession (WebStateM conn sess st) = sess

Methods

runQuery :: (SpockConn (WebStateM conn sess st) -> IO a) -> WebStateM conn sess st a Source #

getState :: WebStateM conn sess st (SpockState (WebStateM conn sess st)) Source #

getSessMgr :: WebStateM conn sess st (SpockSessionManager (SpockConn (WebStateM conn sess st)) (SpockSession (WebStateM conn sess st)) (SpockState (WebStateM conn sess st))) Source #

getSpockCfg :: WebStateM conn sess st (SpockCfg (SpockConn (WebStateM conn sess st)) (SpockSession (WebStateM conn sess st)) (SpockState (WebStateM conn sess st))) Source #

data SessionManager (m :: Type -> Type) conn sess st Source #

getCsrfToken :: SpockActionCtx ctx conn sess st Text Source #

Get the CSRF token for the current user. This token must be sent on all non GET requests via a post parameter or HTTP-Header if spc_csrfProtection is turned on. See configuration SpockCfg documentation for more information

getClientCsrfToken :: SpockActionCtx ctx conn sess st (Maybe Text) Source #

Get the CSRF token sent by the client. You should not need to call this manually if spc_csrfProtection is turned on.

csrfCheck :: SpockActionCtx ctx conn sess st () Source #

Check that the client sent a valid CSRF token. You should not need to call this manually in non GET requests if spc_csrfProtection is turned on.

Accessing internals

type WebStateM conn sess st = WebStateT conn sess st (ResourceT IO) Source #

Shared application services over ResourceT IO. This is the base monad underneath both route registration and request actions in full Spock. Helpers here can use getState and runQuery, but have no request body, response, hook context, or current visitor's session. Those require the action layer. Lift such a helper into an action or registration block with lift; use runSpockIO with an existing environment to run it from IO.

data WebStateT conn sess st (m :: Type -> Type) a Source #

Add the application's WebState environment to an underlying monad m. conn, sess, and st select the connection, session value, and shared state types; a is the computation's result. This is a reader of an existing environment, not a mutable state transformer. Put an IORef or TVar in st when shared state needs to change, with suitable synchronization.

Applications normally use WebStateM, the resource-managed IO specialization.

Instances

Instances details
MonadBaseControl b m => MonadBaseControl b (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

liftBaseWith :: (RunInBase (WebStateT conn sess st m) b -> b a) -> WebStateT conn sess st m a

restoreM :: StM (WebStateT conn sess st m) a -> WebStateT conn sess st m a

MonadBase b m => MonadBase b (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

liftBase :: b α -> WebStateT conn sess st m α

MonadTrans t => HasSpock (t (WebStateM conn sess st)) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

Associated Types

type SpockConn (t (WebStateM conn sess st)) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockConn (t (WebStateM conn sess st)) = conn
type SpockState (t (WebStateM conn sess st)) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockState (t (WebStateM conn sess st)) = st
type SpockSession (t (WebStateM conn sess st)) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockSession (t (WebStateM conn sess st)) = sess

Methods

runQuery :: (SpockConn (t (WebStateM conn sess st)) -> IO a) -> t (WebStateM conn sess st) a Source #

getState :: t (WebStateM conn sess st) (SpockState (t (WebStateM conn sess st))) Source #

getSessMgr :: t (WebStateM conn sess st) (SpockSessionManager (SpockConn (t (WebStateM conn sess st))) (SpockSession (t (WebStateM conn sess st))) (SpockState (t (WebStateM conn sess st)))) Source #

getSpockCfg :: t (WebStateM conn sess st) (SpockCfg (SpockConn (t (WebStateM conn sess st))) (SpockSession (t (WebStateM conn sess st))) (SpockState (t (WebStateM conn sess st)))) Source #

HasSpock (WebStateM conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

Associated Types

type SpockConn (WebStateM conn sess st) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockConn (WebStateM conn sess st) = conn
type SpockState (WebStateM conn sess st) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockState (WebStateM conn sess st) = st
type SpockSession (WebStateM conn sess st) 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockSession (WebStateM conn sess st) = sess

Methods

runQuery :: (SpockConn (WebStateM conn sess st) -> IO a) -> WebStateM conn sess st a Source #

getState :: WebStateM conn sess st (SpockState (WebStateM conn sess st)) Source #

getSessMgr :: WebStateM conn sess st (SpockSessionManager (SpockConn (WebStateM conn sess st)) (SpockSession (WebStateM conn sess st)) (SpockState (WebStateM conn sess st))) Source #

getSpockCfg :: WebStateM conn sess st (SpockCfg (SpockConn (WebStateM conn sess st)) (SpockSession (WebStateM conn sess st)) (SpockState (WebStateM conn sess st))) Source #

MonadTransControl (WebStateT conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

liftWith :: Monad m => (Run (WebStateT conn sess st) -> m a) -> WebStateT conn sess st m a

restoreT :: Monad m => m (StT (WebStateT conn sess st) a) -> WebStateT conn sess st m a

MonadTrans (WebStateT conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

lift :: Monad m => m a -> WebStateT conn sess st m a

Monad m => MonadReader (WebState conn sess st) (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

ask :: WebStateT conn sess st m (WebState conn sess st)

local :: (WebState conn sess st -> WebState conn sess st) -> WebStateT conn sess st m a -> WebStateT conn sess st m a

reader :: (WebState conn sess st -> a) -> WebStateT conn sess st m a

Applicative m => Applicative (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

pure :: a -> WebStateT conn sess st m a

(<*>) :: WebStateT conn sess st m (a -> b) -> WebStateT conn sess st m a -> WebStateT conn sess st m b

liftA2 :: (a -> b -> c) -> WebStateT conn sess st m a -> WebStateT conn sess st m b -> WebStateT conn sess st m c

(*>) :: WebStateT conn sess st m a -> WebStateT conn sess st m b -> WebStateT conn sess st m b

(<*) :: WebStateT conn sess st m a -> WebStateT conn sess st m b -> WebStateT conn sess st m a

Functor m => Functor (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

fmap :: (a -> b) -> WebStateT conn sess st m a -> WebStateT conn sess st m b

(<$) :: a -> WebStateT conn sess st m b -> WebStateT conn sess st m a

Monad m => Monad (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

(>>=) :: WebStateT conn sess st m a -> (a -> WebStateT conn sess st m b) -> WebStateT conn sess st m b

(>>) :: WebStateT conn sess st m a -> WebStateT conn sess st m b -> WebStateT conn sess st m b

return :: a -> WebStateT conn sess st m a

MonadIO m => MonadIO (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

liftIO :: IO a -> WebStateT conn sess st m a

type SpockConn (t (WebStateM conn sess st)) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockConn (t (WebStateM conn sess st)) = conn
type SpockSession (t (WebStateM conn sess st)) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockSession (t (WebStateM conn sess st)) = sess
type SpockState (t (WebStateM conn sess st)) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockState (t (WebStateM conn sess st)) = st
type SpockConn (WebStateM conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockConn (WebStateM conn sess st) = conn
type SpockSession (WebStateM conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockSession (WebStateM conn sess st) = sess
type SpockState (WebStateM conn sess st) Source # 
Instance details

Defined in Web.Spock.Internal.Monad

type SpockState (WebStateM conn sess st) = st
type StT (WebStateT conn sess st) a Source # 
Instance details

Defined in Web.Spock.Internal.Types

type StT (WebStateT conn sess st) a = a
type StM (WebStateT conn sess st m) a Source # 
Instance details

Defined in Web.Spock.Internal.Types

type StM (WebStateT conn sess st m) a = ComposeSt (WebStateT conn sess st) m a

data WebState conn sess st Source #

The application environment: connection pool, session manager, configuration, and shared state. It does not contain a particular request.

Instances

Instances details
Monad m => MonadReader (WebState conn sess st) (WebStateT conn sess st m) Source # 
Instance details

Defined in Web.Spock.Internal.Types

Methods

ask :: WebStateT conn sess st m (WebState conn sess st)

local :: (WebState conn sess st -> WebState conn sess st) -> WebStateT conn sess st m a -> WebStateT conn sess st m a

reader :: (WebState conn sess st -> a) -> WebStateT conn sess st m a

getSpockHeart :: MonadTrans t => t (WebStateM conn sess st) (WebState conn sess st) Source #

Read the heart of Spock. This is useful if you want to construct your own monads that work with runQuery and getState using runSpockIO

runSpockIO :: WebState conn sess st -> WebStateM conn sess st a -> IO a Source #

Run an action inside of Spocks core monad. This allows you to use runQuery and getState

getSpockPool :: MonadTrans t => t (WebStateM conn sess st) (Pool conn) Source #

Read the connection pool of Spock. This is useful if you want to construct your own monads that work with runQuery and getState using runSpockIO