(api & body)
Returns a ring handler wrapped in compojure.api.middleware/api-middlware. Creates the route-table at api creation time and injects that into the request via middlewares. Api and the mounted api-middleware can be configured by optional options map as the first parameter:
(api
{:formats [:json-kw :edn :transit-msgpack :transit-json]
:exceptions {:handlers {:compojure.api.exception/default my-logging-handler}}
:api {:invalid-routes-fn (constantly nil)}
:swagger {:spec "/swagger.json"
:ui "/api-docs"
:data {:info {:version "1.0.0"
:title "My API"
:description "the description"}}}}
(context "/api" []
...))
:api
.
compojure.api.routes/log-invalid-child-routes
api-middleware
from api.compojure.api.swagger/swagger-routes
for details.Opinionated chain of middlewares for web apis. Takes optional options-map.
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}
.
:exceptions for compojure.api.middleware/wrap-exceptions (nil to unmount it)
:type
key in ExceptionInfo data.:format for ring-middleware-format middlewares (nil to unmount it)
[:json-kw :edn]
{:transit-json {:handlers readers}}
{: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).
Returns a ring handler wrapped in compojure.api.middleware/api-middlware. Creates the route-table at api creation time and injects that into the request via middlewares. Api and the mounted api-middleware can be configured by optional options map as the first parameter: (api {:formats [:json-kw :edn :transit-msgpack :transit-json] :exceptions {:handlers {:compojure.api.exception/default my-logging-handler}} :api {:invalid-routes-fn (constantly nil)} :swagger {:spec "/swagger.json" :ui "/api-docs" :data {:info {:version "1.0.0" :title "My API" :description "the description"}}}} (context "/api" [] ...)) ### direct api options: - **:api** All api options are under `:api`. - **:invalid-routes-fn** A 2-arity function taking handler and a sequence of invalid routes (not satisfying compojure.api.route.Routing) setting value to nil ignores invalid routes completely. defaults to `compojure.api.routes/log-invalid-child-routes` - **:disable-api-middleware?** boolean to disable the `api-middleware` from api. - **:swagger** Options to configure the Swagger-routes. Defaults to nil. See `compojure.api.swagger/swagger-routes` for details. ### api-middleware 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).
(defapi name & body)
Defines an api.
API middleware options:
Opinionated chain of middlewares for web apis. Takes optional options-map.
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}
.
:exceptions for compojure.api.middleware/wrap-exceptions (nil to unmount it)
:type
key in ExceptionInfo data.:format for ring-middleware-format middlewares (nil to unmount it)
[:json-kw :edn]
{:transit-json {:handlers readers}}
{: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).
Defines an api. API middleware 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).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close