reitit

teodorlu 2026-03-08T10:45:47.151169Z

Hi! Is it possible to write my router data to get qualified keywords out of path parameters? I've currently got this:

(-> @!last :reitit.core/match :path-params)
  ;; => {:slug "enklere-7"}
But I want :doc/slug, not :slug, as that's the well known attribute the rest of my app talks about. Also, thanks for making Reitit! It has just worked for me for several years! 🙌 Edit: moved details to thread.

teodorlu 2026-03-08T10:46:11.090479Z

More details: The router part of my app is:

["/doc/:slug" {:get #'serve-page
               :name :page-registry/doc}]
I was hoping I could give the slug a qualified keyword. So far, my reading of the documentation has been unfruitful. I hoped for something like:
[["doc" :doc/slug] {:get #'serve-page
                    :name :page-registry/doc}]
;; or, more vebosely, but keep string on the left,
["/doc/:slug" {:get #'serve-page
               :name :page-registry/doc
               :rename-params {:slug :doc/slug}}]
When I do get it as [:doc/slug "enklere-7"], I can do nice stuff like automatically provide Datomic entities for the referenced document, check whether it actually exists, etc, with generic page machinery instead of muddling individual pages with error handling.

teodorlu 2026-03-08T10:52:50.679109Z

If qualified keywords for parameters isn't supported, I'd love advice on how to "plug this in" for myself.

teodorlu 2026-03-08T11:02:40.081539Z

Ultimately, I want a request model like this:

{:request/id #uuid "85b45e6d-a617-4286-9c99-594f1c3a0c6c"
 :session/id #uuid "2be72578-6d49-4685-88b5-1a789f2c9a84"
 :doc/slug "enklere-7"}
, and quickly parse the ring request into my request model as close to the edge of my system as possible.

opqdonut 2026-03-09T06:28:20.997699Z

You should be able to use "/doc/{doc/slug}" as the pattern and get out a qualified kw

🙏 1
🤩 1
opqdonut 2026-03-09T06:29:29.857019Z

Documented here: https://cljdoc.org/d/metosin/reitit/0.10.0/doc/basics/route-syntax

teodorlu 2026-03-09T09:31:07.251269Z

That solves my problem exactly. Thank you!

(def handle identity)

(-> {:request-method :get
     :uri "/doc/blabla"}
    ((reitit.ring/ring-handler
      (reitit.ring/router
       ["/doc/{doc/slug}" {:get #'handle}])))
    :path-params)
;; => {:doc/slug "blabla"}

teodorlu 2026-03-09T09:31:55.325849Z

I think "your keywords can have namespaces" would be worth an explicit mention on the doc page, I didn't understand I could do just that.

opqdonut 2026-03-09T09:40:10.301189Z

on the page I just linked? or somewhere more prominent?

teodorlu 2026-03-09T13:06:15.311449Z

At least on that page, that's what I intended. Personally, I believe parsing straight into qualified keywords is a great feature. If I was writing a router library, I'd want namespaced attributes all the way out to the edge of my system. So I'd want to see them in early Reitit examples too.

opqdonut 2026-03-09T13:26:35.313049Z

I was just wondering because the start of that page says > Parameters can also be wrapped in brackets, enabling use of qualified keywords {user/id}, {*user/path} Maybe some of the examples could have qualified kws?

teodorlu 2026-03-09T13:28:48.348489Z

You're right! I missed that. Examples would definitely have helped 👍

opqdonut 2026-03-09T13:38:59.457809Z

how's this? https://github.com/metosin/reitit/pull/781/changes

opqdonut 2026-03-09T13:41:27.740269Z

NB. the {:foo/bar} version of the syntax is not yet released, it was implemented recently in https://github.com/metosin/reitit/pull/770

💯 2
teodorlu 2026-03-09T13:42:30.337369Z

That looks excellent to me! Glad you put a visual example of :user/id in the introduction test as well. Easy to reconize when looking for qualified keywords!

opqdonut 2026-03-09T13:42:58.320589Z

thanks for the feedback! I'll try to get a new release out this week so you can use the colon version 🙂

❤️ 1
teodorlu 2026-03-09T13:43:48.397069Z

Thank you! Both for the prompt help and the prompt documentation improvements 🙏

🙏 1