Question

I have the following Compojure routes:

(defroutes my-handler
  (GET "/:my-model-id" [id] (render-my-model (parse-int id))))

It is unfortunate that, for every route that I define this way, I have to manually add a call to parse the incoming integer.

I have created Ring middleware that crawls through any form-params and request-params, and parses anything that looks like it might be an integer. However, this middleware does not apply to the custom-defined Compojure routes.

Does anybody know how I could get Compojure to automatically handle the integer-parsing? Can I somehow hook it up to my existing middleware?

Was it helpful?

Solution

Unfortunately compojure will directly invoke the function that is generated from your route definition after it has parsed the params.

AFAIC the only way to get in between is either to modify compojures codebase directly or to use Robert Hooke (by technomancy) on assoc-route-params in https://github.com/weavejester/compojure/blob/master/src/compojure/core.clj#L30

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top