Streamline the use of Components as interceptors.
The definterceptor macro is used to implement a record that extends
[[IntoInterceptor]] and so can be used an interceptor.
Streamline the use of Components as interceptors. The [[definterceptor]] macro is used to implement a record that extends [[IntoInterceptor]] and so can be used an interceptor.
(component->interceptor interceptor-name component)Converts a component into an interceptor. The component must implement
at least one of the Handler, OnEnter, OnLeave, or OnError protocols.
A component can implement the [[IntoInterceptor]] protocol and base the
-interceptor method on this function.
Returns an interceptor record.
Converts a component into an interceptor. The component must implement at least one of the [[Handler]], [[OnEnter]], [[OnLeave]], or [[OnError]] protocols. A component can implement the [[IntoInterceptor]] protocol and base the `-interceptor` method on this function. Returns an interceptor record.
(definterceptor record-name fields & opts+specs)Defines an interceptor component, as a Clojure record. The interceptor's name will be the record's name as a namespace qualified keyword.
After the optional options map, and before the normal protocol/method specs, additional methods may be added:
(handle [this context])(enter [this context])(leave [this context])(error [this context exception])For each of these, definterceptor will provide the matching protocol.
Example:
(definteceptor upcase []
(enter [_ context] (update-in context [:request :query-params :id] string/upper-case)))
The class name will match the record-name (which is typically kebab-cased).
That is (definterceptor foo-bar ...) will generate the same class name as
(defrecord foo-bar ...) even though this is not the normal Pascal Case naming
convention for most records.
The record implements the [[IntoInterceptor]] protocol; see component->interceptor.
The normal map->record and ->record construction functions are generated.
Defines an interceptor component, as a Clojure record. The interceptor's name will be the record's name as a namespace qualified keyword. After the optional options map, and before the normal protocol/method specs, additional methods may be added: - `(handle [this context])` - `(enter [this context])` - `(leave [this context])` - `(error [this context exception])` For each of these, `definterceptor` will provide the matching protocol. Example: ``` (definteceptor upcase [] (enter [_ context] (update-in context [:request :query-params :id] string/upper-case))) ``` The class name will match the record-name (which is typically kebab-cased). That is `(definterceptor foo-bar ...)` will generate the same class name as `(defrecord foo-bar ...)` even though this is not the normal Pascal Case naming convention for most records. The record implements the [[IntoInterceptor]] protocol; see [[component->interceptor]]. The normal `map->record` and `->record` construction functions are generated.
(handle _ request)Handles a request map and returns a response map, or a channel that conveys the response map.
Handles a request map and returns a response map, or a channel that conveys the response map.
(enter _ context)Corresponds to the :enter phase of a standard interceptor; passed the context and returns the (new) context, or a core.async channel that will convey the new context.
Corresponds to the :enter phase of a standard interceptor; passed the context and returns the (new) context, or a core.async channel that will convey the new context.
(error _ context exception)Corresponds to the :error phase of a standard interceptor; passed the context and an exception, and returns the (new) context, or a core.async channel that will convey the new context.
Corresponds to the :error phase of a standard interceptor; passed the context and an exception, and returns the (new) context, or a core.async channel that will convey the new context.
(leave _ context)Corresponds to the :leave phase of a standard interceptor; passed the context and returns the (new) context, or a core.async channel that will convey the new context.
Corresponds to the :leave phase of a standard interceptor; passed the context and returns the (new) context, or a core.async channel that will convey the new context.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |