salvo-rs / salvo

A powerful web framework built with a simplified design.
https://salvo.rs
Apache License 2.0
3.15k stars 184 forks source link

Rename hoop #867

Closed clarnx closed 1 week ago

clarnx commented 1 month ago

Is your feature request related to a problem? Please describe. A quick Google search of the word hoop does not describe anything related to middleware.

Describe the solution you'd like A clear and concise description of an alternative name for hoop will be ideal since most developers are familiar with the word middleware in other frameworks or programming languages. Salvo is simple enough to attract newer developers learning Rust and coming from Laravel, Express.js, and Django backgrounds. Laravel, Express.js, and Django all use the word middleware.

Describe alternatives you've considered A suggestion in my opinion as an alternative name to hoop can be middleware.

Router::new()
    .middleware(check_authed)
    .path("writers")
chrislearn commented 1 month ago

Hoop is a very suitable word. I don’t like the word middleware because it is too long.

clarnx commented 1 month ago

Hoop is a very suitable word. I don’t like the word middleware because it is too long.

Thanks for the response. @chrislearn Another way to know if the community wants hoop or middleware is to create a poll for the community to choose to keep hoop or replace it with middleware.

If you still want to keep hoop, another alternative to achieving this is that hoop remains and then you add middleware which functions just like hoop for those who want to use it to make their code more relatable to other developers on a project. So basically middleware will just return hoop.

astoring commented 4 weeks ago

My personal opinion is that changing the name is useless. Middleware is a very basic concept. Even beginners only need to look at the example or the documentation to know that hoop is middleware.

Adding another middleware method will inevitably make people wonder what the relationship between the two functions middleware and hoop is, which will confuse users. If you really want to add it, you must mark it as a deprecated function.

TheAwiteb commented 3 weeks ago

I don't think there is any need for this, if you really need to write middleware instead of hoop, create an extension trait like this

The code ```rust use salvo::logging::Logger; use salvo::prelude::*; mod traits_ext { use salvo::{Handler, Router}; // https://crates.io/crates/easy-ext #[easy_ext::ext] pub impl Router { fn middleware(self, m: impl Handler) -> Self { self.hoop(m) } } } use traits_ext::*; #[handler] async fn hello() -> &'static str { "Hello World" } #[tokio::main] async fn main() { tracing_subscriber::fmt().init(); let acceptor = TcpListener::new("127.0.0.1:5800").bind().await; let router = Router::new().middleware(Logger::new()).get(hello); tracing::info!("Server listening on http://127.0.0.1:5800"); Server::new(acceptor).serve(router).await; } ```
clarnx commented 3 weeks ago

@TheAwiteb thanks for sharing how to add an implementation of middleware without the need of adding it from source. I think this will be a better approach.