Common interface for web frameworks?

I'm coming from the Ruby world and one thing that I really like in the ecosystem is interoperability of various tools and libraries, especially in context of web development. For those not familiar: in Ruby there is a library called rack that provides an interface for web frameworks. One interesting thing that it enables is to share middleware libraries between different frameworks like Ruby on Rails or Sinatra. For example there is a library called Warden, which provides authentication. When used in frameworks there is sometimes an abstraction built on top of it, but all of the heavy lifting is done in Warden, so you don't have to write the same thing for every framework out there.

With so many frameworks like Actix, Axum, Warp, Rocket etc. it seems wasteful to implement all of the plugins for each of them. That's why I was wondering - do you think it would make sense to try create a set of interfaces (traits?) that could be used by web frameworks allowing for a common interface for some of the functionality? (mainly middleware, but also maybe some kind of handling requests etc)

2 Likes

That would be great :+1:

One immediate complication is the existence of both sync and async code in Rust.
It means that at the very least there will have to be 2 sets of traits.

And on top of that it would require various projects in various stages of maturity to kind of break open their architectures in favor of this common API.

I'm not gonna say it's impossible, but if I were a betting man, I wouldn't take that bet.

I think tower is intended to be something like that? Axum uses it and I think warp is compatible with it as well, meaning you can use tower middleware in both axum and warp projects. Not sure about rocket and actix-web, I wasn't able to find anything.

3 Likes