Fork me on GitHub
#reitit
<
2021-07-05
>
Yehonathan Sharvit10:07:16

A reitit newbie question: why is it important that routes have names?

Vincent Cantin10:07:45

My 2 cents: When you want to redirect to a different route, you use its name instead of copy/pasting its url.

☝️ 2
juhoteperi13:07:02

Why do you think it is important that routes have names? In frontend it is useful when generating hrefs from route tree, in backend it isn't often that needed. In reitit either the handler fn or name are just part of match data, and reitit-core doesn't care about either. The ring adapter uses handler fn, reitit match-by-name (from core or frontend) uses the name.

juhoteperi13:07:23

So I don't think it necessarily is "important", it is just useful in some cases.

lsenjov22:07:26

If you move the path of your route around, you don’t want to be refactoring the paths in every place that calls it. Far less fragile to say “give me the href of this route with these args”

Yehonathan Sharvit09:07:05

Thank you guys for your insights @U8MJBRSR5 @U061V0GG2 and @U24QP2D4J

Yehonathan Sharvit18:07:23

Is it possible to define the routing table in terms of names only and to provide a separate map of names to handlers?

lsenjov22:07:36

I mean, you could walk your routing table and add in the handlers from an external map?

lsenjov22:07:41

You could add a bottom level middleware that takes the route and calls the handler yourself? It smells really bad though

Alexander Moskvichev19:07:18

Hi. I'm trying to write a spec for this route /api/debug?level=1&page[p]=10 Here is route ["/debug" {:get {:parameters {:query {:level int? (keyword "page[p]") int?}}                        :handler    (fn [{{:keys [query]} :parameters}] (response/ok {:query query}))}}] I'm using reitit.coercion.spec Works perfect, but I need the parameter "page[p]" to be optional. Edit: trying (s/def (keyword ":" "page[p]") int?) ...:opt-un [(keyword ":" "page[p]")] but it didn't work. An error message is "Assert failed: k must be namespaced keyword or resolvable symbol (c/and (ident? k) (namespace k))"