Safe Haskell | None |
---|---|
Language | Haskell98 |
- runSpock :: Port -> IO Middleware -> IO ()
- runSpockNoBanner :: Port -> IO Middleware -> IO ()
- spockAsApp :: IO Middleware -> IO Application
- spockT :: MonadIO m => (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
- spockLimT :: forall m. MonadIO m => Maybe Word64 -> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
- spockConfigT :: forall m. MonadIO m => SpockConfig -> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
- type SpockT = SpockCtxT ()
- data SpockCtxT ctx m a
- data Path as pathState :: [*] -> PathState -> *
- root :: Path ([] *) Open
- type Var a = Path ((:) * a ([] *)) Open
- var :: (Typeable * a, PathPiece a) => Path ((:) * a ([] *)) Open
- static :: String -> Path ([] *) Open
- (<//>) :: Path as Open -> Path bs ps -> Path (Append as bs) ps
- renderRoute :: Path as Open -> HVectElim as Text
- subcomponent :: Monad m => Path `[]` Open -> SpockCtxT ctx m () -> SpockCtxT ctx m ()
- prehook :: forall m ctx ctx'. MonadIO m => ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
- get :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- post :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- getpost :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- head :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- put :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- delete :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- patch :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- hookRoute :: forall xs ctx m ps. (HasRep xs, Monad m) => StdMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- hookRouteCustom :: forall xs ctx m ps. (HasRep xs, Monad m) => Text -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- hookAny :: Monad m => StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- hookAnyCustom :: Monad m => Text -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- data StdMethod :: *
- middleware :: Monad m => Middleware -> SpockCtxT ctx m ()
- module Web.Spock.Action
- data SpockConfig = SpockConfig {
- sc_maxRequestSize :: Maybe Word64
- sc_errorHandler :: Status -> ActionCtxT () IO ()
- defaultSpockConfig :: SpockConfig
- hookRoute' :: forall xs ctx m ps. (HasRep xs, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- hookAny' :: Monad m => SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m ()
- data SpockMethod
- newtype HttpMethod = HttpMethod {}
Lauching Spock
runSpock :: Port -> IO Middleware -> IO () Source
Run a Spock application. Basically just a wrapper around run
.
runSpockNoBanner :: Port -> IO Middleware -> IO () Source
Like runSpock
, but does not display the banner "Spock is running on port XXX" on stdout.
spockAsApp :: IO Middleware -> IO Application Source
Convert a middleware to an application. All failing requests will result in a 404 page
Spock's route definition monad
spockT :: MonadIO m => (forall a. m a -> IO a) -> SpockT m () -> IO Middleware Source
Create a raw spock application with custom underlying monad
Use runSpock
to run the app or spockAsApp
to create a Wai.Application
The first argument is request size limit in bytes. Set to Nothing
to disable.
spockLimT :: forall m. MonadIO m => Maybe Word64 -> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware Source
spockConfigT :: forall m. MonadIO m => SpockConfig -> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware Source
Like spockT
, but with additional configuration for request size and error
handlers passed as first parameter.
Defining routes
Rendering routes
Hooking routes
subcomponent :: Monad m => Path `[]` Open -> SpockCtxT ctx m () -> SpockCtxT ctx m () Source
Define a subcomponent. Usage example:
subcomponent "site" $ do get "home" homeHandler get ("misc" <//> var) $ -- ... subcomponent "admin" $ do get "home" adminHomeHandler
The request /site/home will be routed to homeHandler and the request /admin/home will be routed to adminHomeHandler
prehook :: forall m ctx ctx'. MonadIO m => ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m () Source
Specify an action that will be run before all subroutes. It can modify the requests current context
get :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb GET
and the given route match
post :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb POST
and the given route match
getpost :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb 'GET'/'POST' and the given route match
head :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb HEAD
and the given route match
put :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb PUT
and the given route match
delete :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb DELETE
and the given route match
patch :: (HasRep xs, MonadIO m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when the HTTP verb PATCH
and the given route match
hookRoute :: forall xs ctx m ps. (HasRep xs, Monad m) => StdMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when a standard HTTP verb and the given route match
hookRouteCustom :: forall xs ctx m ps. (HasRep xs, Monad m) => Text -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when a custom HTTP verb and the given route match
hookAny :: Monad m => StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m () 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 :: Monad m => Text -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m () 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
data StdMethod :: *
HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).
Adding Wai.Middleware
middleware :: Monad m => Middleware -> SpockCtxT ctx m () Source
Hook wai middleware into Spock
Actions
module Web.Spock.Action
Config
data SpockConfig Source
SpockConfig | |
|
defaultSpockConfig :: SpockConfig Source
Default Spock configuration. No restriction on maximum request size; error handler simply prints status message as plain text.
Internals
hookRoute' :: forall xs ctx m ps. (HasRep xs, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when a HTTP verb and the given route match
hookAny' :: Monad m => SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source
Specify an action that will be run when a HTTP verb matches but no defined route matches. The full path is passed as an argument
data SpockMethod Source
The SpockMethod
allows safe use of http verbs via the MethodStandard
constructor and StdMethod
,
and custom verbs via the MethodCustom
constructor.
MethodStandard !HttpMethod | Standard HTTP Verbs from |
MethodCustom !Text | Custom HTTP Verbs using |