| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Web.Spock.Core
Synopsis
- 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
- spockConfigT :: MonadIO m => SpockConfig -> (forall a. m a -> IO a) -> SpockT m () -> IO Middleware
- type SpockT = SpockCtxT ()
- data SpockCtxT ctx (m :: Type -> Type) a
- data Path (as :: [Type]) (pathState :: PathState)
- root :: Path ('[] :: [Type]) 'Open
- type Var a = Path '[a] 'Open
- data AltVar a b
- var :: (Typeable a, FromHttpApiData a) => Path '[a] 'Open
- static :: String -> Path ('[] :: [Type]) 'Open
- trailingSlash :: forall (as :: [Type]). Path as 'Open -> Path as 'Open
- (<//>) :: forall (as :: [Type]) (bs :: [Type]) (ps :: PathState). Path as 'Open -> Path bs ps -> Path (Append as bs) ps
- (<.>) :: forall (as :: [Type]) (bs :: [Type]). Path as 'Open -> Path bs 'Open -> Path (Append as bs) 'Open
- wildcard :: Path '[Text] 'Closed
- renderRoute :: forall (as :: [Type]). AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text
- renderRouteWith :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as Text
- renderRouteEncoded :: forall (as :: [Type]). AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text
- renderRouteEncodedWith :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> 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 ()
- get :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- post :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- getpost :: forall (xs :: [Type]) t (m :: Type -> Type) ctx (ps :: PathState). (HasRep xs, RouteM t, Monad m, Monad (t ctx m)) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- head :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- put :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- delete :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- patch :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookRoute :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => StdMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookRouteCustom :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Text -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookAny :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- hookAnyCustom :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => Text -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- hookRouteAll :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookAnyAll :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- data StdMethod
- middleware :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => Middleware -> t ctx m ()
- module Web.Spock.Action
- data SpockConfig = SpockConfig {
- sc_maxRequestSize :: Maybe Word64
- sc_errorHandler :: Status -> ActionCtxT () IO ()
- sc_logError :: Text -> IO ()
- sc_logging :: Maybe LoggingConfig
- sc_slashPolicy :: SlashPolicy
- data SlashPolicy
- defaultSpockConfig :: SpockConfig
- hookRoute' :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookAny' :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- data SpockMethod
- newtype HttpMethod = HttpMethod {}
Lauching Spock
runSpock :: Port -> IO Middleware -> IO () Source #
Run a Spock application using run from Network.Wai.Handler.Warp.
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.
spockConfigT :: 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.
type SpockT = SpockCtxT () Source #
Register routes with empty context. m is the base monad used by both
registration and request actions; the final result is normally ().
Pass a runner for m to spockT to build the middleware.
data SpockCtxT ctx (m :: Type -> Type) a Source #
Register routes whose handlers use ActionCtxT ctx m. Registration runs
when the application is built, while the registered handlers and prehooks
run for matching requests. ctx is supplied by prehook, m provides base
effects, and a is the registration result. lift enters m at setup time.
Instances
| RouteM SpockCtxT Source # | |
Defined in Web.Spock.Core Methods addMiddleware :: forall (m :: Type -> Type) ctx. Monad m => Middleware -> SpockCtxT ctx m () Source withPrehook :: forall (m :: Type -> Type) ctx ctx'. MonadIO m => ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m () Source wireAny :: forall (m :: Type -> Type) ctx. Monad m => SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source wireRoute :: forall (m :: Type -> Type) (xs :: [Type]) (ps :: PathState) ctx. (Monad m, HasRep xs) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> SpockCtxT ctx m () Source | |
| MonadTrans (SpockCtxT ctx) Source # | |
Defined in Web.Spock.Core | |
| Monad m => Applicative (SpockCtxT ctx m) Source # | |
Defined in Web.Spock.Core Methods pure :: a -> SpockCtxT ctx m a (<*>) :: SpockCtxT ctx m (a -> b) -> SpockCtxT ctx m a -> SpockCtxT ctx m b liftA2 :: (a -> b -> c) -> SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m c (*>) :: SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m b (<*) :: SpockCtxT ctx m a -> SpockCtxT ctx m b -> SpockCtxT ctx m a | |
| Functor m => Functor (SpockCtxT ctx m) Source # | |
Defined in Web.Spock.Core | |
| Monad m => Monad (SpockCtxT ctx m) Source # | |
| MonadIO m => MonadIO (SpockCtxT ctx m) Source # | |
Defined in Web.Spock.Core | |
Defining routes
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.
Instances
| (Eq a, Eq b) => Eq (AltVar a b) | |
| (Ord a, Ord b) => Ord (AltVar a b) | |
| (Read a, Read b) => Read (AltVar a b) | |
| (Show a, Show b) => Show (AltVar a b) | |
| (FromHttpApiData a, FromHttpApiData b) => FromHttpApiData (AltVar a b) | |
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 Source #
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 Source #
Render a route applying path pieces
renderRouteWith :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as Text Source #
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 Source #
Render a URL with each complete path segment percent-encoded.
renderRouteEncodedWith :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVectElim as Text Source #
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 () Source #
Specify an action that will be run before all subroutes. It can modify the requests current context
get :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when the HTTP verb GET and the given route match
post :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when the HTTP verb POST and the given route match
getpost :: forall (xs :: [Type]) t (m :: Type -> Type) ctx (ps :: PathState). (HasRep xs, RouteM t, Monad m, Monad (t ctx m)) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
head :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when the HTTP verb HEAD and the given route match
put :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when the HTTP verb PUT and the given route match
delete :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when the HTTP verb DELETE and the given route match
patch :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when the HTTP verb PATCH and the given route match
hookRoute :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => StdMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when a standard HTTP verb and the given route match
hookRouteCustom :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Text -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when a custom HTTP verb and the given route match
hookAny :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> t 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 :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => Text -> ([Text] -> ActionCtxT ctx m ()) -> t 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
hookRouteAll :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run regardless of the HTTP verb
hookAnyAll :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => ([Text] -> ActionCtxT ctx m ()) -> t ctx m () 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).
Since: http-types-0.2.0
Instances
| Eq StdMethod | |||||
| Ord StdMethod | |||||
Defined in Network.HTTP.Types.Method | |||||
| Data StdMethod | Since: http-types-0.12.4 | ||||
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 | |||||
Defined in Network.HTTP.Types.Method | |||||
| Enum StdMethod | |||||
Defined in Network.HTTP.Types.Method | |||||
| Generic StdMethod | |||||
Defined in Network.HTTP.Types.Method Associated Types
| |||||
| Ix StdMethod | |||||
| Read StdMethod | |||||
| Show StdMethod | |||||
| type Rep StdMethod # | Since: http-types-0.12.4 | ||||
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 () Source #
Hook wai middleware into Spock
Actions
module Web.Spock.Action
Config
data SpockConfig Source #
Constructors
| SpockConfig | |
Fields
| |
data SlashPolicy #
How empty path segments are treated. The compatibility default ignores every empty segment. Strict policies preserve internal and trailing slashes. Redirects are performed by the HTTP adapter, using strict registry matching.
Constructors
| IgnoreSlashes | |
| StrictSlashes | |
| RedirectTrailingSlashes |
Instances
| Eq SlashPolicy | |
Defined in Web.Routing.SafeRouting | |
| Read SlashPolicy | |
Defined in Web.Routing.SafeRouting Methods readsPrec :: Int -> ReadS SlashPolicy readList :: ReadS [SlashPolicy] readPrec :: ReadPrec SlashPolicy readListPrec :: ReadPrec [SlashPolicy] | |
| Show SlashPolicy | |
Defined in Web.Routing.SafeRouting Methods showsPrec :: Int -> SlashPolicy -> ShowS show :: SlashPolicy -> String showList :: [SlashPolicy] -> ShowS | |
defaultSpockConfig :: SpockConfig Source #
Default Spock configuration. No restriction on maximum request size; error handler simply prints status message as plain text and all errors are logged to stderr.
Internals
hookRoute' :: forall (xs :: [Type]) t (m :: Type -> Type) (ps :: PathState) ctx. (HasRep xs, RouteM t, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
Specify an action that will be run when a HTTP verb and the given route match
hookAny' :: forall t (m :: Type -> Type) ctx. (RouteM t, Monad m) => SpockMethod -> ([Text] -> ActionCtxT ctx m ()) -> t 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.
Constructors
| MethodStandard !HttpMethod | Standard HTTP Verbs from |
| MethodCustom !Text | Custom HTTP verbs represented as |
| MethodAny | Match any HTTP verb |
Instances
newtype HttpMethod Source #
Constructors
| HttpMethod | |
Fields | |
Instances
| Eq HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire | |||||
| Bounded HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire | |||||
| Enum HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire Methods succ :: HttpMethod -> HttpMethod pred :: HttpMethod -> HttpMethod toEnum :: Int -> HttpMethod fromEnum :: HttpMethod -> Int enumFrom :: HttpMethod -> [HttpMethod] enumFromThen :: HttpMethod -> HttpMethod -> [HttpMethod] enumFromTo :: HttpMethod -> HttpMethod -> [HttpMethod] enumFromThenTo :: HttpMethod -> HttpMethod -> HttpMethod -> [HttpMethod] | |||||
| Generic HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire Associated Types
| |||||
| Show HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire Methods showsPrec :: Int -> HttpMethod -> ShowS show :: HttpMethod -> String showList :: [HttpMethod] -> ShowS | |||||
| Hashable HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire | |||||
| type Rep HttpMethod Source # | |||||
Defined in Web.Spock.Internal.Wire type Rep HttpMethod = D1 ('MetaData "HttpMethod" "Web.Spock.Internal.Wire" "Spock-core-0.16.1.0-inplace" 'True) (C1 ('MetaCons "HttpMethod" 'PrefixI 'True) (S1 ('MetaSel ('Just "unHttpMethod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 StdMethod))) | |||||