More controllable composition of Ring middlewares.
This library is attempt to resolve following difficulties with usage of Ring middlewares:
->
macro what makes hard to reason about
actual request/response flow between wrappers.Ring handlers are build from handler function and sequence of middleware configurations using handler/build function.
Default type of ring handler is sync handler. To produce async ring handler
use either :async
option or {:async true}
in handler's meta.
Every middleware configuration is a map with keys:
{:keys [wrap]}
:wrap
– a function (fn [handler] new-handler)
to wrap handler.{:keys [enter leave]}
:enter
— a function (fn [request] new-request)
to transform request.:leave
– a function (fn [response request] new-response)
to transform
response.Maps with :wrap
and :enter
/:leave
causes exception.
Only middlewares with :wrap
can short-circuit, :enter
/:leave
just modify
request/response.
The middlewares are applied in the order:
:wrap
/:enter
middlewares only.:leave
/:wrap
receives response from next middlewares.See also walkthrough.
The strojure.ring-control.config.ring-middleware
namespace contains
configuration for middlewares in ring libraries.
The libraries should be added in project dependencies explicitly for configuration to be used.
An implementation of the ring-defaults using ring-control configurations:
Can you improve this documentation? These fine people already did:
serioga & Sergey TrofimovEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close