Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type RoutingApplication m = Request -> (RouteResult Response -> m Response) -> m Response
- data RouteResult a
- = Fail ServantErr
- | FailFatal !ServantErr
- | Route !a
- toApplication :: forall m. MonadSnap m => RoutingApplication m -> Application m
- responseLBS :: Status -> [(CI ByteString, ByteString)] -> ByteString -> Response
- runAction :: MonadSnap m => Delayed m env (m a) -> env -> Request -> (RouteResult Response -> m r) -> (a -> RouteResult Response) -> m r
- data Delayed m env c where
- newtype DelayedM m a = DelayedM {
- runDelayedM :: Request -> m (RouteResult a)
- emptyDelayed :: Monad m => Proxy (m :: * -> *) -> RouteResult a -> Delayed m env a
- delayedFail :: Monad m => ServantErr -> DelayedM m a
- delayedFailFatal :: Monad m => ServantErr -> DelayedM m a
- withRequest :: (Request -> DelayedM m a) -> DelayedM m a
- addCapture :: forall env a b captured m. Monad m => Delayed m env (a -> b) -> (captured -> DelayedM m a) -> Delayed m (captured, env) b
- addMethodCheck :: Monad m => Delayed m env a -> DelayedM m () -> Delayed m env a
- addAuthCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b
- addBodyCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b
- addAcceptCheck :: Monad m => Delayed m env a -> DelayedM m () -> Delayed m env a
- passToServer :: Delayed m env (a -> b) -> (Request -> a) -> Delayed m env b
- runDelayed :: Monad m => Delayed m env a -> env -> Request -> m (RouteResult a)
Documentation
type RoutingApplication m Source #
= Request | the request, the field |
-> (RouteResult Response -> m Response) | |
-> m Response |
data RouteResult a Source #
The result of matching against a path in the route tree.
Fail ServantErr | Keep trying other paths. The |
FailFatal !ServantErr | Don't try other paths. |
Route !a |
Functor RouteResult Source # | |
Eq a => Eq (RouteResult a) Source # | |
Read a => Read (RouteResult a) Source # | |
Show a => Show (RouteResult a) Source # | |
toApplication :: forall m. MonadSnap m => RoutingApplication m -> Application m Source #
responseLBS :: Status -> [(CI ByteString, ByteString)] -> ByteString -> Response Source #
runAction :: MonadSnap m => Delayed m env (m a) -> env -> Request -> (RouteResult Response -> m r) -> (a -> RouteResult Response) -> m r Source #
DelayedM | |
|
emptyDelayed :: Monad m => Proxy (m :: * -> *) -> RouteResult a -> Delayed m env a Source #
A Delayed
without any stored checks.
delayedFail :: Monad m => ServantErr -> DelayedM m a Source #
Fail with the option to recover.
delayedFailFatal :: Monad m => ServantErr -> DelayedM m a Source #
Fail fatally, i.e., without any option to recover.
withRequest :: (Request -> DelayedM m a) -> DelayedM m a Source #
Gain access to the incoming request.
addCapture :: forall env a b captured m. Monad m => Delayed m env (a -> b) -> (captured -> DelayedM m a) -> Delayed m (captured, env) b Source #
Add a capture to the end of the capture block.
addMethodCheck :: Monad m => Delayed m env a -> DelayedM m () -> Delayed m env a Source #
Add a method check to the end of the method block.
addAuthCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b Source #
Add an auth check to the end of the auth block.
addBodyCheck :: Monad m => Delayed m env (a -> b) -> DelayedM m a -> Delayed m env b Source #
Add a body check to the end of the body block.
addAcceptCheck :: Monad m => Delayed m env a -> DelayedM m () -> Delayed m env a Source #
Add an accept header check to the beginning of the body block. There is a tradeoff here. In principle, we'd like to take a bad body (400) response take precedence over a failed accept check (406). BUT to allow streaming the body, we cannot run the body check and then still backtrack. We therefore do the accept check before the body check, when we can still backtrack. There are other solutions to this, but they'd be more complicated (such as delaying the body check further so that it can still be run in a situation where we'd otherwise report 406).
passToServer :: Delayed m env (a -> b) -> (Request -> a) -> Delayed m env b Source #
Many combinators extract information that is passed to
the handler without the possibility of failure. In such a
case, passToServer
can be used.
runDelayed :: Monad m => Delayed m env a -> env -> Request -> m (RouteResult a) Source #
Run a delayed server. Performs all scheduled operations in order, and passes the results from the capture and body blocks on to the actual handler.
This should only be called once per request; otherwise the guarantees about effect and HTTP error ordering break down.