compojure icon indicating copy to clipboard operation
compojure copied to clipboard

Extract unparsed path from context

Open Nivl opened this issue 3 years ago • 3 comments

When extracting a route path using (:compojure/route req) we can retrieve the raw unparsed path. So for example if my path is /hello/:name and a user hits /hello/world, I can retrieve /hello/:name. This is extremely useful for tracing and to capture metrics in general.

Now the issue is that this isn't (doesn't seem?) doable when using a context. For example, given this context:

(context "/nested/:greeting" [_]
           (GET "/world" [_] {:status 200}))

If a user hits /nested/hello/world, we can retreive /nested/hello from the request (in the :context), but not /nested/:greeting.

Our goal is to have the /nested/:greeting/world string available for our telemetry data.

It would be amazing if this could be supported.

Nivl avatar Apr 14 '22 20:04 Nivl

The :uri key will give you the full path.

weavejester avatar Apr 14 '22 22:04 weavejester

@weavejester :uri would provide the full parsed path. For example instead of providing me with /nested/:greeting/world it would provide /nested/hello/world.

Nivl avatar Apr 14 '22 22:04 Nivl

Ah, apologies, I misread and you're right that this isn't currently supported. I would be fine with a PR that adds a :compojure/full-route key to the request map.

weavejester avatar Apr 14 '22 23:04 weavejester