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 :: 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 :: [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
- (<//>) :: Path as 'Open -> Path bs ps -> Path (Append as bs) ps
- wildcard :: Path '[Text] 'Closed
- renderRoute :: AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text
- prehook :: (RouteM t, MonadIO m) => ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
- get :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- post :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- getpost :: (HasRep xs, RouteM t, Monad m, Monad (t ctx m)) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- head :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- put :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- delete :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- patch :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookRoute :: (HasRep xs, RouteM t, Monad m) => StdMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookRouteCustom :: (HasRep xs, RouteM t, Monad m) => Text -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookAny :: (RouteM t, Monad m) => StdMethod -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- hookAnyCustom :: (RouteM t, Monad m) => Text -> ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- hookRouteAll :: (HasRep xs, RouteM t, Monad m) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookAnyAll :: (RouteM t, Monad m) => ([Text] -> ActionCtxT ctx m ()) -> t ctx m ()
- data StdMethod
- middleware :: (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 ()
- defaultSpockConfig :: SpockConfig
- hookRoute' :: (HasRep xs, RouteM t, Monad m) => SpockMethod -> Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m ()
- hookAny' :: (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. 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.
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.
data SpockCtxT ctx m a Source #
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 => Monad (SpockCtxT ctx m) Source # | |
Functor m => Functor (SpockCtxT ctx m) Source # | |
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 # | |
MonadIO m => MonadIO (SpockCtxT ctx m) Source # | |
Defined in Web.Spock.Core |
Defining routes
data Path (as :: [Type]) (pathState :: PathState) #
Instances
(a ~ ('[] :: [Type]), pathState ~ 'Open) => IsString (Path a pathState) | |
Defined in Web.Routing.Combinators Methods fromString :: String -> Path a pathState # |
wildcard :: Path '[Text] 'Closed #
Matches the rest of the route. Should be the last part of the path.
Rendering routes
renderRoute :: AllHave ToHttpApiData as => Path as 'Open -> HVectElim as Text Source #
Render a route applying path pieces
Hooking routes
prehook :: (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 :: (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 :: (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 :: (HasRep xs, RouteM t, Monad m, Monad (t ctx m)) => Path xs ps -> HVectElim xs (ActionCtxT ctx m ()) -> t ctx m () Source #
head :: (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 :: (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 :: (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 :: (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 :: (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 :: (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 :: (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 :: (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 :: (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 :: (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).
Instances
Bounded StdMethod | |
Enum StdMethod | |
Defined in Network.HTTP.Types.Method Methods 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 | |
Read StdMethod | |
Show StdMethod | |
Ix StdMethod | |
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 # |
Adding Wai.Middleware
middleware :: (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
|
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' :: (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' :: (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 using |
MethodAny | Match any HTTP verb |
Instances
Eq SpockMethod Source # | |
Defined in Web.Spock.Internal.Wire | |
Generic SpockMethod Source # | |
Defined in Web.Spock.Internal.Wire Associated Types type Rep SpockMethod :: Type -> Type # | |
Hashable SpockMethod Source # | |
Defined in Web.Spock.Internal.Wire | |
type Rep SpockMethod Source # | |
Defined in Web.Spock.Internal.Wire type Rep SpockMethod = D1 ('MetaData "SpockMethod" "Web.Spock.Internal.Wire" "Spock-core-0.14.0.0-K2pbC2tVT8aBDrFhli6pMZ" 'False) (C1 ('MetaCons "MethodStandard" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HttpMethod)) :+: (C1 ('MetaCons "MethodCustom" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "MethodAny" 'PrefixI 'False) (U1 :: Type -> Type))) |
newtype HttpMethod Source #
Constructors
HttpMethod | |
Fields |