Releases: metosin/compojure-api
Releases · metosin/compojure-api
1.0.0
1.0.0-RC2
1.0.0-RC1
- Move from compile-time to runtime route resolution.
- Most of the internal macro magic has been vaporized
- Uses internally (invokable) Records & Protocols, allowing easier integration to 3rd party libs like Liberator
- even for large apps (100+ routes), route compilation takes now millis, instead of seconds
- sub-routes can be created with normal functions (or values), making it easier to:
- pass in app-level dependencies from libs like Component
- reuse shared request-handling time parameters like path-parameters and authorization info
(defn more-routes [db version]
(routes
(GET "/version" []
(ok {:version version}))
(POST "/thingie" []
(ok (thingie/create db)))))
(defn app [db]
(api
(context "/api/:version" []
:path-params [version :- s/Str]
(more-routes db version)
(GET "/kikka" []
(ok "kukka")))))
Breaking changes
- BREAKING Vanilla Compojure routes will not produce any swagger-docs (as they do not satisfy the
Routing
protocol. They can still be used for handling request, just without docs.- a new api-level option
[:api :invalid-routes-fn]
to declare how to handle routes not satisfying
theRouting
protocol. Default implementation logs invalid routes as WARNINGs.
- a new api-level option
- BREAKING compojure.core imports are removed from
compojure.api.sweet
:let-request
,routing
,wrap-routes
- BREAKING Asterix (
*
) is removed from route macro & function names, as there is no reason to mix compojure-api & compojure route macros.GET*
=>GET
ANY*
=>ANY
HEAD*
=>HEAD
PATCH*
=>PATCH
DELETE*
=>DELETE
OPTIONS*
=>OPTIONS
POST*
=>PUT
context*
=>context
defroutes*
=>defroutes
- BREAKING
swagger-docs
andswagger-ui
are now longer incompojure.api.sweet
- Syntax was hairy and when configuring the spec-url it needed to be set to both in order to work
- In future, there are multiple ways of setting the swagger stuff:
- via api-options
:swagger
(has no defaults) - via
swagger-routes
function, mounting both theswagger-ui
andswagger-docs
and wiring them together- by default, mounts the swagger-ui to
/
and the swagger-spec to/swagger.json
- by default, mounts the swagger-ui to
- via the old
swagger-ui
&swagger-docs
(need to be separately imported fromcompojure.api.swagger
). - see https://github.com/metosin/compojure-api/wiki/Swagger-integration for details
- via api-options
(defapi app
(swagger-routes)
(GET "/ping" []
(ok {:message "pong"})))
(defapi app
{:swagger {:ui "/", :spec "/swagger.json"}}
(GET "/ping" []
(ok {:message "pong"})))
- BREAKING: api-level coercion option is now a function of
request => type => matcher
as it is documented.
Previously required atype => matcher
map. Options are checked againsttype => matcher
coercion input, and a
descriptive error is thrown when api is created with the old options format. - BREAKING: Renamed
middlewares
tomiddleware
and:middlewares
key (restructuring) to:middleware
- will break at macro-expansion time with helpful exception
- BREAKING: Middleware must be defined as data: both middleware macro and :middleware restructuring
take a vector of middleware containing either- a) fully configured middleware (function), or
- b) a middleware templates in form of
[function args]
- You can also use anonymous or lambda functions to create middleware with correct parameters,
these are all identical:[[wrap-foo {:opts :bar}]]
[#(wrap-foo % {:opts :bar})]
[(fn [handler] (wrap-foo handler {:opts :bar}))]
- Similar to duct
- BREAKING: (Custom restructuring handlers only)
:parameters
key used byrestructure-param
has been renamed to:swagger
.- will break at macro-expansion time with helpful exception
- BREAKING
public-resource-routes
&public-resources
are removed fromcompojure.api.middleware
. - BREAKING:
compojure.api.legacy
namespace has been removed.
Migration guide
https://github.com/metosin/compojure-api/wiki/Migration-Guide-to-1.0.0
Other stuff
- Additional route functions/macros in
compojure.api.core
:routes
&letroutes
, just like in the Compojure, but supportingRouting
undocumented
- works just likeroutes
but without any route definitions. Can be used to wrap legacy routes which setting the api option to fail on missing docs.
- top-level
api
is now just function, not a macro. It takes an optional options maps and a top-level route function. - Coercer cache is now at api-level with 10000 entries.
- Code generated from restructured route macros is much cleaner now
- Coercion is on by default for standalone (apiless) endpoints.
(fact "coercion is on for apiless routes"
(let [route (GET "/x" []
:query-params [x :- Long]
(ok))]
(route {:request-method :get :uri "/x" :query-params {}}) => throws))
- Removed deps:
[backtick "0.3.3"]
0.24.5
- Fixed path parameter handling in cases where path parameter is followed by an extension
(#196, metosin/ring-swagger#82) - Updated ring-swagger
- Added
compojure.api.exception/with-logging
helper to add logging to exception handlers.- Check extended wiki guide on exception handling
- Updated deps:
[metosin/ring-swagger "0.22.3"] is available
0.24.4
0.24.3
0.24.2
- Memoize coercers (for
schema
&matcher
-input) for better performance.- Tests show 0-40% lower latency,
depending on input & output schema complexity. - Tested by sending json-strings to
api
and reading json-string out. - Measured a 80% lower latency with a real world large Schema.
- Tests show 0-40% lower latency,
- Updated deps:
[potemkin "0.4.2"] is available but we use "0.4.1"
0.24.1
- uses
[Ring-Swagger "0.22.1"]
clojure.tools.logging
is used with default uncaugt exception handling if it's found
on the classpath. Fixes #172.- Both
api
anddefapi
produce identical swagger-docs. Fixes #159 - allow any swagger data to be overriden at runtime either via swagger-docs or via middlewares. Fixes #170.
[metosin/ring-swagger "0.22.1"] is available but we use "0.22.0"
[metosin/ring-swagger-ui "2.1.3-4"] is available but we use "2.1.3-2"
[prismatic/plumbing "0.5.2] is available but we use "0.5.1"
0.24.0
- BREAKING: Dropped support for Clojure 1.6
- BREAKING: Supports and depends on Schema 1.0.
- Uses upstream ring-middleware-format
instead of Metosin fork. - Uses now linked instead of
ordered for maps where order matters. swagger-ui
now supports passing arbitrary options toSwaggerUI
(metosin/ring-swagger#67).- Updated deps:
[prismatic/schema "1.0.3"] is available but we use "0.4.4"
[prismatic/plumbing "0.5.1] is available but we use "0.4.4"
[metosin/schema-tools "0.7.0"] is available but we use "0.5.2"
[metosin/ring-swagger "0.22.0"] is available but we use "0.21.0"
[metosin/ring-swagger-ui "2.1.3-2"] is available but we use "2.1.2"