Liking cljdoc? Tell your friends :D

strojure.ring-stack.core


as-handler-wrapcljmultimethod

(as-handler-wrap obj)

Coerce object to Ring handler wrapper.

Coerce object to Ring handler wrapper.
sourceraw docstring

as-request-wrapcljmultimethod

(as-request-wrap obj)

Coerce object to Ring request wrapper, the function (fn [request] new-request).

Coerce object to Ring request wrapper, the function
`(fn [request] new-request)`.
sourceraw docstring

as-response-wrapcljmultimethod

(as-response-wrap obj)

Coerce object to Ring response wrapper, the function (fn [response request] new-response).

Coerce object to Ring response wrapper, the function
`(fn [response request] new-response)`.
sourceraw docstring

middleware-typeclj

(middleware-type obj)

Returns dispatch value for middleware object.

  • for map with :type returns its value
  • for keyword returns this keyword
  • for objects with :type in meta returns its value
  • for functions returns IFn
  • otherwise returns (class obj)
Returns dispatch value for middleware object.

- for map with `:type` returns its value
- for keyword returns this keyword
- for objects with `:type` in meta returns its value
- for functions returns `IFn`
- otherwise returns `(class obj)`
sourceraw docstring

require-configcljmultimethod

(require-config obj)

Returns configuration {:keys [outer enter leave inner]} where every key contains sequence of middleware types to be presented in configuration before the middleware.

Returns configuration `{:keys [outer enter leave inner]}` where every key
contains sequence of middleware types to be presented in configuration before
the middleware.
sourceraw docstring

wrap-handlerclj

(wrap-handler handler {:keys [outer enter leave inner ignore-required]})

Returns ring handler wrapped by middlewares in configuration map:

  • :outer Standard ring middlewares to wrap around all other wrappers.
  • :enter Ring request wrapping functions (fn [request] new-request).
  • :leave Ring response wrapping functions (fn [response request] new-response). The function receive same request as wrapping handler itself.
  • :inner Standard ring middlewares to wrap just around handler after :enter and before :leave.

Wrapper are applying in direct order:

;; Call `(enter1 request)` before `(enter2 request)`.
{:enter [enter1
         enter2]}

Configuration groups are applied as they are listed above:

  • Request flow:
    • :outer -> :enter -> :inner -> handler.
  • Response flow:
    • handler -> :inner -> :leave -> :outer.

Such configuration allows to distinguish between request/response handlers, control order of wrappers more easy and naturally comparing with usage of standard ring middlewares only.

Wrapping functions can be defined with types using multimethods as-handler-wrap, as-request-wrap, as-response-wrap and be referred in configuration:

{:enter [::enter1
         ::enter2
         {:type ::enter3 :opt1 true :opt2 false}]}

Same type can be defined as request wrapper and as response wrapper. They should be specified in :enter and :leave independently.

In this case we can also define dependency of ::enter2 on ::enter2 using require-config multimethod:

(defmethod require-config ::enter2 [_]
  {:enter [::enter1]})

;; This fails with exception about missing middleware:
(wrap-handler handler {:enter [::enter2]})

;; This fails with exception about wrong order:
(wrap-handler handler {:enter [::enter2 ::enter1]})

;; But this succeeds anyway:
(wrap-handler handler {:enter [::enter2]
                       :ignore-required [::enter1]})
Returns ring handler wrapped by middlewares in configuration map:

- `:outer` Standard ring middlewares to wrap around all other wrappers.
- `:enter` Ring request wrapping functions `(fn [request] new-request)`.
- `:leave` Ring response wrapping functions `(fn [response request] new-response)`.
           The function receive same `request` as wrapping handler itself.
- `:inner` Standard ring middlewares to wrap just around `handler` after
           `:enter` and before `:leave`.

Wrapper are applying in direct order:

    ;; Call `(enter1 request)` before `(enter2 request)`.
    {:enter [enter1
             enter2]}

Configuration groups are applied as they are listed above:

- Request flow:
    - `:outer` -> `:enter` -> `:inner` -> handler.
- Response flow:
    - handler -> `:inner` -> `:leave` -> `:outer`.

Such configuration allows to distinguish between request/response handlers,
control order of wrappers more easy and naturally comparing with usage of
standard ring middlewares only.

Wrapping functions can be defined with types using multimethods
[[as-handler-wrap]], [[as-request-wrap]], [[as-response-wrap]] and be referred
in configuration:

    {:enter [::enter1
             ::enter2
             {:type ::enter3 :opt1 true :opt2 false}]}

Same type can be defined as request wrapper and as response wrapper. They
should be specified in `:enter` and `:leave` independently.

In this case we can also define dependency of `::enter2` on `::enter2` using
[[require-config]] multimethod:

    (defmethod require-config ::enter2 [_]
      {:enter [::enter1]})

    ;; This fails with exception about missing middleware:
    (wrap-handler handler {:enter [::enter2]})

    ;; This fails with exception about wrong order:
    (wrap-handler handler {:enter [::enter2 ::enter1]})

    ;; But this succeeds anyway:
    (wrap-handler handler {:enter [::enter2]
                           :ignore-required [::enter1]})
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close