Liking cljdoc? Tell your friends :D

compojure.api.middleware


->mime-typesclj

(->mime-types formats)
source

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.
  • :format for ring-middleware-format middlewares (nil to unmount it)

    • :formats sequence of supported formats, e.g. [:json-kw :edn]
    • :params-opts for ring.middleware.format-params/wrap-restful-params, e.g. {:transit-json {:handlers readers}}
    • :response-opts for ring.middleware.format-params/wrap-restful-response, e.g. {:transit-json {:handlers writers}}
  • :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 :body, :string and :response. Defaults to (constantly compojure.api.middleware/default-coercion-matchers) 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.

- **:format**                    for ring-middleware-format middlewares (nil to unmount it)
    - **:formats**                 sequence of supported formats, e.g. `[:json-kw :edn]`
    - **:params-opts**             for *ring.middleware.format-params/wrap-restful-params*,
                                   e.g. `{:transit-json {:handlers readers}}`
    - **:response-opts**           for *ring.middleware.format-params/wrap-restful-response*,
                                   e.g. `{:transit-json {:handlers writers}}`

- **: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 :body, :string and :response.
                                 Defaults to `(constantly compojure.api.middleware/default-coercion-matchers)`
                                 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

coercion-matchersclj

(coercion-matchers request)
source

coercion-request-ksclj

source

CoercionTypeclj

sourceraw docstring

compose-middlewareclj

(compose-middleware middleware)
source

default-coercion-matchersclj

source

get-componentsclj

(get-components req)
source

get-optionsclj

(get-options request)

Extracts compojure-api options from the request.

Extracts compojure-api options from the request.
sourceraw docstring

handle-req-errorclj

(handle-req-error e handler request)
source

middleware-fnclj

(middleware-fn middleware)
source

mime-typesclj

(mime-types format)
source

no-response-coercionclj

source

rethrow-exceptions?clj

source

serializable?clj

(serializable? _ {:keys [body] :as response})

Predicate which returns true if the response body is serializable. That is, return type is set by :return compojure-api key or it's a collection.

Predicate which returns true if the response body is serializable.
That is, return type is set by :return compojure-api key or it's
a collection.
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-optionsclj

(wrap-options handler options)

Injects compojure-api options into the request.

Injects compojure-api options into the request.
sourceraw docstring

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

× close