reitit

pieterbreed 2024-08-06T14:42:24.445439Z

Hi everyone; I'm trying to create two routes that look the same (to reitit) but are not the same (ito payload, query-parameters &c.) Something like "phone/data/specific" & "phone/data/:other" where :other will never be "specific" . At the moment reitit throws an exception for conflicting routes. I noticed in the docs that there is a {:conflicting true} config I can apply, and it's mentioned this is for legacy. Is this an appropriate way to achieve the outcome that I want? Or will I be forced to create a completely seperate endpoint/route?

Eva O 2024-08-09T16:32:56.588629Z

@yannvahalewyn REST doesn't dictate url shape. Maybe something like /resource/new and /resource/items/:id could work?

wevrem 2024-08-06T16:25:00.186599Z

Could you have one route, then deal with the different cases inside the handler?

(def routes
  ["phone/data/:seg"
   {:get (fn [{:as request {:keys [seg]} :path-params}]
           (case seg
             "specific" (handler-specific request)
             (handler-other request)))}])

pieterbreed 2024-08-06T18:47:11.105019Z

The route data and parameter specs/validation is different, otherwise i would do it like you suggest

wevrem 2024-08-06T20:30:10.683389Z

I am actually using {:conflicting true} myself in my route tables, but I’ve considered this as an alternative. In my project I’m still nailing down the specific routes, but once that is sort of finalized, I’ll see what tweaks I can make and hopefully won’t need to allow conflicts.

yannvahalewyn 2024-08-16T11:13:30.031799Z

@eoogbe Indeed rest is not a protocol and yes those would work. But there are common conventions adopted when making restful url schemes as described https://restfulapi.net/resource-naming/ and seen in this https://medium.com/@shubhangirajagrawal/the-7-restful-routes-a8e84201f206 . For me keeping the convention of /products/:id is usually worth the conflicting route πŸ™‚

πŸ‘πŸΏ 1
Eva O 2024-08-19T14:34:18.713999Z

I've been experimenting with a naming convention that doesn't have conflicts: β€’ GET /product/items - Show list of products β€’ GET /product/new - Show form to make new product β€’ POST /product/items - Add product β€’ GET /product/items/:id - Show single product β€’ GET /product/edit/:id - Show form to edit product β€’ PUT /product/items/:id - Update product β€’ DELETE /product/items/:id - Delete product

πŸ‘ŒπŸ½ 1
yannvahalewyn 2024-08-07T09:45:42.930379Z

I also use {:conflicting true}. I have this for /resource/new and /resource/:id paths. If someone knows how to do REST without :conflicting I'd love to hear how

πŸ™πŸ½ 1
daveliepmann 2024-08-07T09:54:50.998419Z

> If someone knows how to do REST without :conflicting I'd love to hear how Could you differentiate between HTTP verbs?

yannvahalewyn 2024-08-07T09:56:53.854949Z

According to REST, new and show are both GET requests and this is also preferable for semantics and browser support.

πŸ‘ 1