pedestal 2024-09-17

How does this look?

Conflicting routes were identified:
:io.pedestal.http.sawtooth-test/get-page (GET /pages/:id) conflicts with route:
 - :io.pedestal.http.sawtooth-test/search-pages (GET /pages/search)
:io.pedestal.http.sawtooth-test/get-user (GET /user/:user-id) conflicts with route:
 - :io.pedestal.http.sawtooth-test/user-search (GET /user/search)
:io.pedestal.http.sawtooth-test/page-content (ANY /pages/*path) conflicts with 2 routes:
 - :io.pedestal.http.sawtooth-test/get-page (GET /pages/:id)
 - :io.pedestal.http.sawtooth-test/search-pages (GET /pages/search)

👍 1
8

The question is, why are the routes in conflict? If the ids could be identified, e.g. by regex, they could be distinguished from search and the conflict would be resolved.

🎯 1

Path and query constraints are considered harmful. There's a full discussion on the web site, but essentially, a route that is matched on path but doesn't match the constraints will (for all but the linear search router) return a 404 response (with no other details). A proper application will not use constraints, and will have an interceptor do those checks, and return a proper 400 response with an explanation.

The report is specific to sawtooth, because sawtooth organizes its routes in such a way that it can perform this analysis. prefix-tree detects some kinds of conflicts as far as I can tell, but throws an exception on the first such conflict.

Looking good! /me hops over to the repo to check out what's cooking!

I'm not aware of another router (at least in the Clojure space) that could do this analysis; compojure and friends are all heavily macro-based, there's no model to analyze.

Looks like maybe retit

➕ 1

yep, AFAIK, reitit also does compile-time optimisations (the equivalent of inlining and dead-code eliminiation, but for routing tables)

it's possible I could speed up sawtooth by building up code and using eval, but I'd rather avoid that. I haven't looked at retit to see if it's doing anything like that. Given that they have invested in implementing a retit router with Pedestal, I'll make sure that the changes I make to the protocols are compatible.

beautiful

I like it. Is this avaible for every type of router?