Understand coercion middleware optimization and mounting
masterReitit optimizes coercion middleware by compiling it against specific routes. The middleware is only mounted if the route explicitly defines :coercion along with either :parameters or :responses.
If a route lacks these keys, the coercion middleware chain will be empty for that route, reducing overhead. You can verify the mounted middleware for a specific route by inspecting the router using reitit.core/match-by-name.
(require '[reitit.core :as r])
;; Querying the compiled middleware chain for a route
(-> (ring/get-router app)
(r/match-by-name ::plus)
:result :post :middleware
(->> (mapv :name)))
; => [::mw/coerce-exceptions ::mw/coerce-request ::mw/coerce-response]
;; A route without coercion defined will have no mounted middleware
(-> (ring/get-router app)
(r/match-by-name ::ping)
:result :get :middleware)
; => []