1.0.0-RC1
Pre-release
Pre-release
- 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"]