Liking cljdoc? Tell your friends :D

io.pedestal.interceptor

Public API for creating interceptors, and various utility fns for common interceptor creation patterns.

Public API for creating interceptors, and various utility fns for
common interceptor creation patterns.
raw docstring

*default-handler-names*clj

If true (the default) then functions converted to interceptor will get a default interceptor name based on the function class name. This name is a real name: routes may take their route name from it.

If false, for compatibility with routes defined for earlier releases, the interceptor gets a name derived the same way, but only as a derived name (as any unnamed interceptor does, see interceptor): it appears in logs, traces, and errors, but a route never takes its route name from it, so such a route needs a route name from elsewhere (an explicit route name, or a Var handler).

The system property io.pedestal.interceptor.disable-default-handler-names (or environment variable PEDESTAL_DISABLE_DEFAULT_HANDLER_NAMES) if true, will default this to false.

If true (the default) then functions converted to interceptor
will get a default interceptor name based on the function class name.
This name is a real name: routes may take their route name from it.

If false, for compatibility with routes defined for earlier releases, the interceptor
gets a name derived the same way, but only as a derived name (as any unnamed interceptor does, see [[interceptor]]):
it appears in logs, traces, and errors, but a route never takes its route name from it,
so such a route needs a route name from elsewhere (an explicit route name, or a Var handler).

The system property `io.pedestal.interceptor.disable-default-handler-names`
(or environment variable `PEDESTAL_DISABLE_DEFAULT_HANDLER_NAMES`)
if true, will default this to false.
sourceraw docstring

component->interceptorclj

(component->interceptor interceptor-name component)

Converts a component record 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 record 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.
sourceraw docstring

definterceptorcljmacro

(definterceptor record-name fields & opts+specs)

Defines an interceptor as a Clojure record. This is specifically useful for components.

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 as a Clojure record. This is specifically useful
 for components.

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.
sourceraw docstring

Handlercljprotocol

handleclj

(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.
source

interceptorclj

(interceptor t)

Given a value, produces and returns an Interceptor (Record)

t can be anything that extends the IntoInterceptor protocol; notably, this includes functions, which will be wrapped as interceptors, but act as handlers (a handler receives the request map and returns the response map).

An interceptor without a :name is given one, derived from the class name of its function: for a handler, the handler function; otherwise its :enter, :leave, or :error function (the first one present). For example, (defn get-order [request] ...) in namespace my.app gives :my.app/get-order, and an anonymous (fn [context] ...) inside (defn audit [] ...) gives :my.app/audit/fn. Such a name appears in logs, traces, and errors, but a route never takes its route name from it. A function built by a combinator, such as partial or comp, gets a generic name from the combinator's class (for example, :clojure.core/partial/fn). To choose the name, give the interceptor a :name (a namespaced keyword).

The mark that the name is derived is kept in the interceptor's metadata: rebuilding the interceptor from a plain map (such as (interceptor (into {} i))), or replacing its metadata, makes the derived name an explicit name, which a route may then take as its route name.

Given a value, produces and returns an Interceptor (Record)

t can be anything that extends the [[IntoInterceptor]] protocol; notably, this includes functions, which
will be wrapped as interceptors, but act as handlers (a handler receives the request map and returns
the response map).

An interceptor without a :name is given one, derived from the class name of its function: for a handler,
the handler function; otherwise its :enter, :leave, or :error function (the first one present).
For example, `(defn get-order [request] ...)` in namespace `my.app` gives `:my.app/get-order`, and an
anonymous `(fn [context] ...)` inside `(defn audit [] ...)` gives `:my.app/audit/fn`.
Such a name appears in logs, traces, and errors, but a route never takes its route name from it.
A function built by a combinator, such as `partial` or `comp`, gets a generic name from the combinator's
class (for example, `:clojure.core/partial/fn`).
To choose the name, give the interceptor a :name (a namespaced keyword).

The mark that the name is derived is kept in the interceptor's metadata: rebuilding the interceptor from a plain
map (such as `(interceptor (into {} i))`), or replacing its metadata, makes the derived name an explicit name,
which a route may then take as its route name.
sourceraw docstring

interceptor-nameclj

(interceptor-name n)

Ensures that an interceptor name (to eventually be the :name key of an Interceptor) is either a keyword or nil. Generally, interceptor names should be namespace-qualified keywords.

Ensures that an interceptor name (to eventually be the :name key of an Interceptor)
is either a keyword or nil.  Generally, interceptor names should be namespace-qualified keywords.
sourceraw docstring

interceptor?clj

(interceptor? o)

Returns true if object o is an instance of the Interceptor record; the result of invoking interceptor.

Returns true if object o is an instance of the Interceptor record; the result of
invoking [[interceptor]].
sourceraw docstring

IntoInterceptorcljprotocol

Conversion into Interceptor, ready for execution as part of an interceptor chain.

Conversion into Interceptor, ready for execution as part of an interceptor chain.

-interceptorclj

(-interceptor t)

Given a value, produce an Interceptor Record.

Given a value, produce an Interceptor Record.
sourceraw docstring

OnEntercljprotocol

enterclj

(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.
source

OnErrorcljprotocol

errorclj

(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.
source

OnLeavecljprotocol

leaveclj

(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.
source

valid-interceptor?clj

(valid-interceptor? o)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close