1

I have a Clojure service that I'm exposing via REST. I have a page defined as:

(defpage "/package_versions/:id" {:keys [id]}
  (do
    (println "ID: " id)
    (if-let [pv (pv/fetch-one (db/keyspace) id)]
      (response/json pv)
      (response/status 404 nil))))

What characters are allowed for id? The slugs 1-2-3, 1|2|3, 1_2_3 all work, but 1.2.3 doesn't. Is there a way to make slugs which contain . work? What are the allowed characters in noir routes? Which code is responsible for this behavior: noir, ring, compojure?

animuson
  • 53,861
  • 28
  • 137
  • 147
MrEvil
  • 7,785
  • 7
  • 36
  • 36

2 Answers2

1

Have a look at the Clout test cases.

The slugs used in the tests don't really have special characters in them so I don't know what characters are legal, but at the end of the file there's an example of how to define a custom route matcher that presumably can be used to match dots if you so desire.

I would expect that you can plug the custom route matcher into Noir with either noir.core/compojure-route or noir.core/custom-handler.

Also, there are tests with literal dots in them, e.g. "/foo.:ext that matches URLs like /foo.txt, so I wouldn't be surprised if it was a feature, not a bug, to not allow dots in slugs.

liwp
  • 6,746
  • 1
  • 27
  • 39
  • So your right, I also posed this question to the clj-group https://groups.google.com/forum/?fromgroups#!topic/clj-noir/KbrxJrafUrU And they referred me to this guide: https://github.com/weavejester/compojure/wiki/Routes-In-Detail – MrEvil Feb 29 '12 at 03:23
  • So the relevant part of that document is: `The :id part will match any sub-path up to the next "/" or "."`. It also states that you can specify your custom regex for sub-path matching inline, e.g. `(defpage ["/user/:id", :id #"[0-9]+"] ...)` in the case of Noir. – liwp Feb 29 '12 at 10:22
0

It should be clout responsible for this, which is a library Compojure uses. You can have a look at wakeful to see one example of setting up different matchers, in particular the use of route-compile.

amalloy
  • 89,153
  • 8
  • 140
  • 205