Liking cljdoc? Tell your friends :D

compojure.api.middleware


api-middlewareclj

(api-middleware handler)
(api-middleware handler options)

Opinionated chain of middlewares for web apis. Takes optional options-map.

Exception handlers

An error handler is a function of exception, ex-data and request to response.

When defining these options, it is suggested to use alias for the exceptions namespace, e.g. [compojure.api.exception :as ex].

Default:

{::ex/request-validation  ex/request-validation-handler
 ::ex/request-parsing     ex/request-parsing-handler
 ::ex/response-validation ex/response-validation-handler
 ::ex/default             ex/safe-handler}

Note: Because the handlers are merged into default handlers map, to disable default handler you need to provide nil value as handler.

Note: To catch Schema errors use {:schema.core/error ex/schema-error-handler}.

Options

  • :exceptions for compojure.api.middleware/wrap-exceptions (nil to unmount it)

    • :handlers Map of error handlers for different exception types, type refers to :type key in ExceptionInfo data.
  • :formats for Muuntaja middleware. Value can be a valid muuntaja options-map, a Muuntaja instance or nil (to unmount it). See https://github.com/metosin/muuntaja/wiki/Configuration for details.

  • :middleware vector of extra middleware to be applied last (just before the handler).

  • :ring-swagger options for ring-swagger's swagger-json method. e.g. {:ignore-missing-mappings? true}

  • :coercion A function from request->type->coercion-matcher, used in endpoint coercion for types :body, :string and :response. Defaults to compojure.api.middleware/default-coercion Setting value to nil disables all coercion.

  • :components Components which should be accessible to handlers using :components restructuring. (If you are using api, you might want to take look at using wrap-components middleware manually.). Defaults to nil (middleware not mounted).

Opinionated chain of middlewares for web apis. Takes optional options-map.

### Exception handlers

An error handler is a function of exception, ex-data and request to response.

When defining these options, it is suggested to use alias for the exceptions namespace,
e.g. `[compojure.api.exception :as ex]`.

Default:

    {::ex/request-validation  ex/request-validation-handler
     ::ex/request-parsing     ex/request-parsing-handler
     ::ex/response-validation ex/response-validation-handler
     ::ex/default             ex/safe-handler}

Note: Because the handlers are merged into default handlers map, to disable default handler you
need to provide `nil` value as handler.

Note: To catch Schema errors use `{:schema.core/error ex/schema-error-handler}`.

### Options

- **:exceptions**                for *compojure.api.middleware/wrap-exceptions* (nil to unmount it)
    - **:handlers**                Map of error handlers for different exception types, type refers to `:type` key in ExceptionInfo data.

- **:formats**                   for Muuntaja middleware. Value can be a valid muuntaja options-map,
                                 a Muuntaja instance or nil (to unmount it). See
                                 https://github.com/metosin/muuntaja/wiki/Configuration for details.

- **:middleware**                vector of extra middleware to be applied last (just before the handler).

- **:ring-swagger**              options for ring-swagger's swagger-json method.
                                 e.g. `{:ignore-missing-mappings? true}`

- **:coercion**                  A function from request->type->coercion-matcher, used
                                 in endpoint coercion for types :body, :string and :response.
                                 Defaults to `compojure.api.middleware/default-coercion`
                                 Setting value to nil disables all coercion.

- **:components**                Components which should be accessible to handlers using
                                 :components restructuring. (If you are using api,
                                 you might want to take look at using wrap-components
                                 middleware manually.). Defaults to nil (middleware not mounted).
sourceraw docstring

api-middleware-defaultsclj

source

api-middleware-optionsclj

(api-middleware-options options)
source

compose-middlewareclj

(compose-middleware middleware)
source

create-muuntajaclj

(create-muuntaja)
(create-muuntaja muuntaja-or-options)
source

default-muuntaja-optionsclj

source

encode?clj

(encode? _ response)

Returns true if the response body is serializable: body is a collection or response has key :compojure.api.meta/serializable?

Returns true if the response body is serializable: body is a
collection or response has key :compojure.api.meta/serializable?
sourceraw docstring

get-componentsclj

(get-components req)
source

get-swagger-dataclj

(get-swagger-data request)

Reads and deep-merges top-level swagger-data from request, pushed in by set-swagger-data.

Reads and deep-merges top-level swagger-data from request,
pushed in by set-swagger-data.
sourceraw docstring

middleware-fnclj

(middleware-fn middleware)
source

set-swagger-dataclj

(set-swagger-data request data)

Add extra top-level swagger-data into a request. Data can be read with get-swagger-data.

Add extra top-level swagger-data into a request.
Data can be read with get-swagger-data.
sourceraw docstring

wrap-coercionclj

(wrap-coercion handler coercion)
source

wrap-componentsclj

(wrap-components handler components)

Assoc given components to the request.

Assoc given components to the request.
sourceraw docstring

wrap-exceptionsclj

(wrap-exceptions handler {:keys [handlers]})

Catches all exceptions and delegates to correct error handler according to :type of Exceptions

  • :handlers - a map from exception type to handler
    • :compojure.api.exception/default - Handler used when exception type doesn't match other handler, by default prints stack trace.
Catches all exceptions and delegates to correct error handler according to :type of Exceptions
- **:handlers** - a map from exception type to handler
  - **:compojure.api.exception/default** - Handler used when exception type doesn't match other handler,
                                           by default prints stack trace.
sourceraw docstring

wrap-formatclj

(wrap-format handler)
(wrap-format handler options)

Muuntaja format middleware. Can be safely mounted on top of multiple api

Muuntaja format middleware. Can be safely mounted on top of multiple api

- **:formats**                   for Muuntaja middleware. Value can be a valid muuntaja options-map,
                                 a Muuntaja instance or nil (to unmount it). See
                                 https://github.com/metosin/muuntaja/wiki/Configuration for details.
sourceraw docstring

wrap-inject-dataclj

(wrap-inject-data handler data)

Injects data into the request.

Injects data into the request.
sourceraw docstring

wrap-swagger-dataclj

(wrap-swagger-data handler data)

Middleware that adds top level swagger-data into request.

Middleware that adds top level swagger-data into request.
sourceraw docstring

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

× close