Skip to content

1.0.0-RC1

Pre-release
Pre-release
Compare
Choose a tag to compare
@Deraen Deraen released this 17 Feb 14:05
· 722 commits to master since this release

compare

  • 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
      the Routing protocol. Default implementation logs invalid routes as WARNINGs.
  • 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 and swagger-ui are now longer in compojure.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 the swagger-ui and swagger-docs and wiring them together
        • by default, mounts the swagger-ui to / and the swagger-spec to /swagger.json
      • via the old swagger-ui & swagger-docs (need to be separately imported from compojure.api.swagger).
      • see https://github.com/metosin/compojure-api/wiki/Swagger-integration for details
(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 a type => matcher map. Options are checked against type => matcher coercion input, and a
    descriptive error is thrown when api is created with the old options format.
  • BREAKING: Renamed middlewares to middleware 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 by restructure-param
    has been renamed to :swagger.
    • will break at macro-expansion time with helpful exception
  • BREAKING public-resource-routes & public-resources are removed from compojure.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 supporting Routing
    • undocumented - works just like routes 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"]