reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Steven Deobald 2020-10-08T12:43:33.076600Z

What is the least-disgusting / most-compatible way to resolve route conflicts to keep URLs structured as Rails does?

["/pali_word_card" {:name ::pali-word-create
                    :post (wrap-spec-validation :entity/pali-word-request pali-word-handler/create)}]
;; conflicting:-
["/pali_word_card/new" {:name ::pali-word-new
                        :get  pali-word-handler/new}]
["/pali_word_card/:id" {:name ::pali-word-show
                        :get  pali-word-handler/show}]
:conflicts nil is a sledgehammer and even :conflicting true feels... heavy. Is there any other way around this?

ikitommi 2020-10-08T13:10:25.080200Z

:conflicts nil is good and could have been the default option. If you have a route table with 100 routes and add a pair of conflicting routes, e.g. /pali_word_card/new & /pali_word_card/:id, those two will be isolated into a separate linear-router, all others will be served with best possible algo.

ikitommi 2020-10-08T13:11:59.081500Z

the perf penalty for non-conflicting routes in that is one extra function call, few nanos in practise.

Steven Deobald 2020-10-08T13:12:38.082Z

oh, wait... conflict errors are to enable perf, not precision?

Steven Deobald 2020-10-08T13:13:21.083Z

(i was worried that :conflicts nil might cause errors)

ikitommi 2020-10-08T13:17:29.086900Z

it’s precision in case you have a masked route, e.g.

[["/kikka/:id"]
 ["/kikka/kukka"]]
-> the second one is effective unreachable.

Steven Deobald 2020-10-08T13:17:55.087600Z

rad. so as long as routes are in order, everything's golden?

ikitommi 2020-10-08T13:18:00.087800Z

yes

Steven Deobald 2020-10-08T13:18:16.088100Z

awesome! thanks

👍 1
ikitommi 2020-10-08T13:20:28.089600Z

the conflict resolver could be smarter and know that

[["/kikka/kikka"]
 ["/kikka/:id"]]
actually is not conflicting as the fixed term(s) comes first. PR welcome 🙂

Steven Deobald 2020-10-08T13:23:25.090400Z

🙂 i'll try to familiarize myself with all the parts of reitit before I try opening a PR. making a note, though.

2020-10-08T13:37:54.092900Z

hi! i’m getting 404 for urls like this: /foo/../bar but /bar respond with 200 looks like reitit is not supporting single- and double-dot path segments, isn’t it?

ikitommi 2020-10-08T13:39:55.094300Z

@delaguardo no, it’s not. you could have something (middleware etc) rewrite the url before it enters routing.

2020-10-08T13:42:52.095800Z

this is how I solve it. wouldn’t it be too much impudence to ask for such a feature included (behind an option) in core router?

Steven Deobald 2020-10-08T14:18:54.097100Z

@ikitommi fwiw, after 5 years away from clojure (and programming in general), it's nice to come back to the scene and find something like reitit. just replaced all my routing in the new app/service we're building and it honestly worked exactly as i've always wanted routing to work in clojure. thank you!

3