Any web frameworks that go beyond segment based routing?

🙋 seeking help & advice

In most web frameworks on other platforms I'm familiar with, you could define a route like:

"/images/${id}-${width}x${height}.${format}"

Unless I'm missing something, that doesn't really seem possible with Axum or Poem. The best you can do is a wildcard route and then write custom Extractors.

It's not the Extractors I really have an issue with as much as the route then being much too broad and over-matching. Which feels like you're then having to write a more complex extractor to cover an entire endpoint, that you'd then call other functions in your handler with, effectively hard-coding route handling into your top-level handler.

Yo dawg, I heard you like routers so I put a router in your router...

Warp's extensibility seems like it can solve this by writing custom filters. It's not beautiful, I assume it wouldn't work with the path! macro, but it can work with the basic combinators, and supports route rejections so you don't accidentally dead-end a request just because you changed the order of your routes. I do worry that Warp doesn't seem to prioritize putting out an official 1.0 given it seems to have been around quite a while.

But the custom filters are not too far off from routing in akka-http (Scala), which is kind of the holy-grail IMO.

Then there's stuff like Node/Fastify, which basically just lets you use regexes for the more complex routes (not generally a fan of regex routes, but at least it's possible to write specific routes there).

It seems like the Rust frameworks I've checked out so far have relatively rudimentary Segment based routing. Are there other Rust frameworks I need to look at? Or am I off-base regarding Axum and Poem?

Here's an Axum issue that appears to go into some detail: https://github.com/tokio-rs/axum/issues/109

For me at least, I think I disagree with the conclusion. Being able to discriminate resources based on extension: /articles/:id (json) vs /articles/:id.xml vs /articles/:id.jpg or /articles/:id.zip is really nice. There's the obvious thumbnail/preview stuff linked as well where it's nice to just be able to request /images/123-640x480.jpg. You certainly can work around this stuff, but the entire point of a router is to help you organize your handlers and surface your interface so you're not depending on manual evaluation and dispatch right?

Posted Jan 8, 2024, 9:49 PM UTC

1917

Comments aren't archived yet

This post had 17 comments on Reddit. Comments for this period haven't been loaded into the archive yet.