tourist/middleware
src/tourist/middleware.tur
Middleware type and middleware chain runner.
Since: v0.1.0
defn
use!
(use! [fn : int] :)
register a middleware function.
Parameters
| fn | (fn [req :int] :int) returning option<Response>: | |
| (none) to continue, (some resp) to short-circuit |
Returns
:int -- middleware handle; consumed by tourist
Example
(use! (fn [req]
(println (req-path req))
(none)))
Since: v0.1.0
defn
mw-item?
(mw-item? [item : int] :)
true if an item handle is a middleware, not a route.
Parameters
| item | :int item handle (from use!, get!, post!, etc.) |
Returns
:bool
Since: v0.1.0
defn
mw-call
(mw-call [mw : int req : int] :)
invoke a middleware on a request.
Parameters
| mw | :int middleware handle from use! | |
| req | :int tourist ctx (request handle) |
Returns
:int -- option<Response>: 0 = none (continue), non-zero = some(resp)
Since: v0.1.0
defn
mw-chain-run
(mw-chain-run [mws : int req : int] :)
run a cons list of middleware handles in order.
Parameters
| mws | :int cons list of middleware handles (0 = empty) | |
| req | :int tourist ctx (request handle) |
Returns
:int -- option<Response>: non-zero some(resp) or 0 for none
Example
(let [opt (mw-chain-run mw-list req)]
(when (not= opt 0) ...))
Since: v0.1.0
Internal definitions
__mw-cons-head-- head of a Turmeric cons list cell.__mw-cons-tail-- tail of a Turmeric cons list cell.