Search code examples
clojurecompojureluminus

compojure get request when route has binds


I use to define my routes in composure like this:

(GET "/home" [req] (home-page req))

and then I have the whole request object available to use inside my handler.

but now I want to use routes with binds, like:

(GET "/details/:id" [id] (details-page id))

in this case, it seems that I have no way to get the request AND the bound arguments at the same time. I tried:

(GET "/details/:id" [id req] (details-page id req))

but req comes nil.

is there any way to get the request on routes with bindings?

I want the bindings so I don't have to do things like:

(GET "/details" [req] (details-page req)) and then have <a href="/details?id=123">...

and I need the request to have access to the session and request headers.

any suggestion?

thanks in advance.


Solution

  • hum... it is not perfect, but I'm going with:

    (GET "/details/:id" req (details-page (-> req :params :id) req))

    this snippet works, and solves my problem, but I would love something simpler (DRY).