HTTP 404 in route response

34 views
Skip to first unread message

cijsse...@gmail.com

unread,
Sep 2, 2019, 3:32:53 PM9/2/19
to pedestal-users
Greetings,

When trying to introduce path-params in my app-route I can't seem to get it right. A minimal failing version looks like this:

(def resp200 (constantly {:status 200}))

(def routes
 
(route/expand-routes #{
     
["/user/:ruleset/submit"           :get resp200 :route-name :submit]
     
["/user/:ruleset/:version/execute" :get resp200 :route-name :execute] }))

(def service {::http/routes routes ::http/type :jetty ::http/port 8080})

wget http://localhost:8080/user/ruleset/submit           -> 401 NOT FOUND

What am I doing wrong? Should I make the route hierarchical?


Paul deGrandis

unread,
Sep 3, 2019, 7:59:31 AM9/3/19
to pedestal-users
Hi there!

Thanks for reaching out on the mailing list.
As a general rule, it's often encourage that people use query-string args instead of path-params where possible. That aside, let's get to the issue at hand.

Pedestal ships with a few different routers that make different trade-offs (features, evaluation order, performance).  Pedestal defaults to a tree-based router when possible, but this has a feature restriction - path-param wildcard values can't also have "hard-coded" values in the route tree (eg:  You can't have `:version` and `submit` at the same level in the path).

However, you can use Pedestal's linear router, which allows you to have the routes setup this way.
In your service map, you can set the :io.pedestal.http/router to :linear-search to change to this router.

More details can be found in the Routing/Router quick docs: http://pedestal.io/reference/routing-quick-reference#_routers

I hope this helps!

Cheers,
Paul

cijsse...@gmail.com

unread,
Sep 3, 2019, 3:25:23 PM9/3/19
to pedestal-users
Hello Paul,

Thanks for the explanation. Indeed, the use of the linear-search router solved my problems. I remember reading path-params take precedence over hardcoded path parts, so it does make more sense now. 

In all honesty, I do think that in this case the paths "/user/:ruleset/submit" and "/user/:ruleset/:version/execute" are non-conflicting (having different path-part counts). I dont know if the prefix-tree restriction ("path-param takes precedence over hardcoded path part") could be made more tolerant in case of path-length differences, without compromising performance or code complexity, but that could make the prefix-tree router arguably better.

But this really a minor quibble on my part. I have no problem dropping down to the linear search router. My current route definition is pretty simple and with some reordering of my current routes (most used in the front) routing will stay optimal. 

So thanks for the help! Pedestal is really great!

Greetings,
Niels
Reply all
Reply to author
Forward
0 new messages