Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- runSpock :: Port -> IO Middleware -> IO ()
- runSpockNoBanner :: Port -> IO Middleware -> IO ()
- spockAsApp :: IO Middleware -> IO Application
- spock :: forall conn sess st. SpockCfg conn sess st -> SpockM conn sess st () -> IO Middleware
- type SpockM conn sess st = SpockCtxM () conn sess st
- type SpockCtxM ctx conn sess st = SpockCtxT ctx (WebStateM conn sess st)
- data Path (as :: [Type]) (pathState :: PathState)
- root :: Path ('[] :: [Type]) 'Open
- type Var a = Path '[a] 'Open
- var :: (Typeable a, FromHttpApiData a) => Path '[a] 'Open
- static :: String -> Path ('[] :: [Type]) 'Open
- (<//>) :: forall (as :: [Type]) (bs :: [Type]) (ps :: PathState). Path as 'Open -> Path bs ps -> Path (Append as bs) ps
- wildcard :: Path '[Text] 'Closed
- renderRoute :: forall (as :: [Type]). AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text
- prehook :: forall t (m :: Type -> Type) ctx ctx'. (RouteM t, MonadIO m) => ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
- type RouteSpec xs ps ctx conn sess st = Path xs ps -> HVectElim xs (SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st ()
- get :: HasRep xs => RouteSpec xs ps ctx conn sess st
- post :: HasRep xs => RouteSpec xs ps ctx conn sess st
- getpost :: HasRep xs => RouteSpec xs ps ctx conn sess st
- head :: HasRep xs => RouteSpec xs ps ctx conn sess st
- put :: HasRep xs => RouteSpec xs ps ctx conn sess st
- delete :: HasRep xs => RouteSpec xs ps ctx conn sess st
- patch :: HasRep xs => RouteSpec xs ps ctx conn sess st
- hookRoute :: HasRep xs => StdMethod -> RouteSpec xs ps ctx conn sess st
- hookRouteCustom :: HasRep xs => Text -> RouteSpec xs ps ctx conn sess st
- hookAny :: StdMethod -> ([Text] -> SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st ()
- hookAnyCustom :: Text -> ([Text] -> SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st ()
- hookRouteAll :: HasRep xs => RouteSpec xs ps ctx conn sess st
- hookAnyAll :: ([Text] -> SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st ()
- data StdMethod
- middleware :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => Middleware -> t ctx m ()
- type SpockAction conn sess st = SpockActionCtx () conn sess st
- type SpockActionCtx ctx conn sess st = ActionCtxT ctx (WebStateM conn sess st)
- module Web.Spock.Action
- class HasSpock m where
- type SpockConn m :: *
- type SpockState m :: *
- type SpockSession m :: *
- runQuery :: (SpockConn m -> IO a) -> m a
- getState :: m (SpockState m)
- getSessMgr :: m (SpockSessionManager (SpockConn m) (SpockSession m) (SpockState m))
- getSpockCfg :: m (SpockCfg (SpockConn m) (SpockSession m) (SpockState m))
- data SessionManager m conn sess st
- module Web.Spock.SessionActions
- getCsrfToken :: SpockActionCtx ctx conn sess st Text
- getClientCsrfToken :: SpockActionCtx ctx conn sess st (Maybe Text)
- csrfCheck :: SpockActionCtx ctx conn sess st ()
- type WebStateM conn sess st = WebStateT conn sess st (ResourceT IO)
- data WebStateT conn sess st m a
- data WebState conn sess st
- getSpockHeart :: MonadTrans t => t (WebStateM conn sess st) (WebState conn sess st)
- runSpockIO :: WebState conn sess st -> WebStateM conn sess st a -> IO a
- getSpockPool :: MonadTrans t => t (WebStateM conn sess st) (Pool conn)
Launching Spock
runSpock :: Port -> IO Middleware -> IO () #
Run a Spock application. Basically just a wrapper around run
.
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 :: forall conn sess st. 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
Defining routes
data Path (as :: [Type]) (pathState :: PathState) #
Instances
(a ~ ('[] :: [Type]), pathState ~ 'Open) => IsString (Path a pathState) | |
Defined in Web.Routing.Combinators fromString :: String -> Path a pathState # |
(<//>) :: forall (as :: [Type]) (bs :: [Type]) (ps :: PathState). Path as 'Open -> Path bs ps -> Path (Append as bs) ps #
Combine two path components
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
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 xs ps ctx conn sess st = Path xs ps -> HVectElim xs (SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st () Source #
get :: HasRep xs => RouteSpec 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 :: HasRep xs => RouteSpec xs ps ctx conn sess st Source #
Specify an action that will be run when the HTTP verb POST
and the given route match
head :: HasRep xs => RouteSpec 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 :: HasRep xs => RouteSpec 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 :: HasRep xs => RouteSpec 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 :: HasRep xs => RouteSpec 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 :: HasRep xs => StdMethod -> RouteSpec 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 :: HasRep xs => Text -> RouteSpec 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 ()) -> SpockCtxM 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 ()) -> SpockCtxM 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 :: HasRep xs => RouteSpec 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 ()) -> SpockCtxM 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
HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).
Instances
Bounded StdMethod | |
Enum StdMethod | |
Defined in Network.HTTP.Types.Method succ :: StdMethod -> StdMethod # pred :: StdMethod -> StdMethod # fromEnum :: StdMethod -> Int # enumFrom :: StdMethod -> [StdMethod] # enumFromThen :: StdMethod -> StdMethod -> [StdMethod] # enumFromTo :: StdMethod -> StdMethod -> [StdMethod] # enumFromThenTo :: StdMethod -> StdMethod -> StdMethod -> [StdMethod] # | |
Eq StdMethod | |
Ord StdMethod | |
Defined in Network.HTTP.Types.Method | |
Read StdMethod | |
Show StdMethod | |
Ix StdMethod | |
Defined in Network.HTTP.Types.Method 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 # |
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 #
The SpockAction
is a specialisation of SpockActionCtx
with a ()
context.
type SpockActionCtx ctx conn sess st = ActionCtxT ctx (WebStateM conn sess st) Source #
The SpockActionCtx
is the monad of all route-actions. You have access
to the context of the request and database, session and state of your application.
module Web.Spock.Action
class HasSpock m where Source #
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
MonadTrans t => HasSpock (t (WebStateM conn sess st)) Source # | |
Defined in Web.Spock.Internal.Monad type SpockConn (t (WebStateM conn sess st)) Source # type SpockState (t (WebStateM conn sess st)) Source # type SpockSession (t (WebStateM conn sess st)) Source # 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 # | |
Defined in Web.Spock.Internal.Monad type SpockConn (WebStateM conn sess st) Source # type SpockState (WebStateM conn sess st) Source # type SpockSession (WebStateM conn sess st) Source # 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 conn sess st Source #
module Web.Spock.SessionActions
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
data WebStateT conn sess st m a Source #
Instances
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
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