Framework
salvo-rs/salvo avatar
salvo-rs/salvo

Salvo treats middleware as a handler on a route branch

A powerful web framework built with a simplified design.

4,467 stars276 forksRustApache-2.0

At a glance

What is it?
Salvo is a Rust web framework whose central bet is that a middleware and an endpoint are the same function, mounted with hoop() on a branch of a route tree. That makes small services short to write, and it moves TLS and OpenAPI support into separate crates you may or may not want.
Who is it for?
Adopt Salvo if you are writing a small to mid-sized async Rust service and want the routing tree, OpenAPI output and ACME setup in one dependency set. Do not adopt it if your team is standardising on Actix Web or Axum, since the handler-as-middleware design pulls you out of that ecosystem's conventions.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 4 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • salvo-rs/salvo4,467 ★ · +29
Star history
Repository2026-09-232026-11-22
salvo-rs/salvo4.4k4.5k

29 Stars in the last 60 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

One function type covers both the endpoint and the middleware

Salvo targets Rust developers who have already decided on Tokio and Hyper but do not want to assemble a server from separate routing, body extraction and TLS crates. The design decision worth arguing about is the one the README files under Middleware = Handler. In most Rust HTTP stacks a middleware is a distinct type implementing Transform, a Service or a Layer, with its own generic bounds and its own error channel. Salvo removes that second concept: `#[handler]` produces one function, and the same function can serve as an endpoint or as a filter.

The audience that gains is anyone writing auth, logging or header logic for a dozen routes and tired of writing the same wrapper three times. Whether that trade is acceptable depends on your middleware, not on the framework's marketing.

hoop() binds middleware to one branch of the router, not to the whole app

Routing is a tree of `Router` values, and the interesting part is where middleware attaches. `Router::with_path("articles").hoop(auth_check).post(create_article).delete(delete_article)` puts the auth check on that branch alone, while a sibling `Router::with_path("articles").get(list_articles)` stays public. Two nodes sharing the same path string is fine, because the tree rather than the path defines the scope.

That design keeps authorisation legible. A reader of the router can see which branch sits behind `auth_check` without tracing a global layer stack, and the branch can later grow more verbs without anyone re-checking a shared filter list. The mechanism has a sharp edge: a new sub-router pushed onto a protected branch inherits the parent's hoop, and a branch added by a different developer can sit outside it. Scope by convention in a builder chain is scope by reading, and reading is the only enforcement.

cargo add salvo tokio with the oapi feature, then bind 127.0.0.1:7878

The framework is published on crates.io as `salvo`, and the scaffolding CLI as `salvo-cli`. Create the crate and pull in the framework and the async runtime together, with the OpenAPI feature enabled:

bash
cargo new hello-salvo
cd hello-salvo
cargo add salvo tokio --features salvo/oapi,tokio/macros

`tokio/macros` is what makes the `#[tokio::main]` attribute expand, so leaving it out fails at compile time rather than at runtime. Put this in `src/main.rs`:

rust
use salvo::prelude::*;

#[handler]
async fn hello() -> &'static str {
    "Hello World"
}

#[tokio::main]
async fn main() {
    let router = Router::new().get(hello);
    let acceptor = TcpListener::new("127.0.0.1:7878").bind().await;
    Server::new(acceptor).serve(router).await;
}

Run it with `cargo run` and request `http://127.0.0.1:7878`. The loopback bind means nothing outside the machine is reachable, which is right for the first run and wrong for a service. If you would rather not type the boilerplate, there is a scaffold command:

bash
cargo install salvo-cli
salvo new my_project

Swapping #[handler] for #[endpoint] is what pulls in the OpenAPI layer

The `oapi` feature is not a documentation toggle bolted on after the fact. Salvo reads the same function signatures to build the OpenAPI description, which is why the README's claim of generated documentation holds up structurally rather than by convention.

The change is one attribute:

rust
#[endpoint]
async fn hello() -> &'static str {
    "Hello World"
}

Because the macro is the source of both the routing table and the schema, a signature cannot drift from its documentation the way a hand-written spec does. The flip side is that the macro is the contract. The README does not document how to opt a single endpoint out of schema generation, and that is the question to ask before committing to the feature on a mixed codebase.

ACME binding to 0.0.0.0:443 assumes a public domain you already own

Automatic certificates are configured on the listener rather than in a separate deployment step:

rust
let listener = TcpListener::new("0.0.0.0:443")
    .acme()
    .add_domain("example.com")
    .http01_challenge(&mut router)
    .quinn("0.0.0.0:443"); // HTTP/3 support

Three assumptions sit in those five lines. `add_domain` needs a name that already resolves to the host and passes the http01 challenge over port 80, so this does not work for an internal service or a laptop. Binding 443 needs privileges or a capability. And `.quinn()` is where HTTP/3 actually arrives, which qualifies the feature list claim of full protocol support out of the box: the third protocol is opt-in at the listener, not a default.

The workspace manifest makes the same point quietly. Every workspace crate is pinned at version `1.1.0` except `salvo-http3`, which sits at `0.7.0`. The HTTP/3 layer has not caught up with the rest of the release train.

Body parsing surfaces as ParseError, which is the API's real failure mode

Handlers take the request, so extracting a typed body is a method rather than a trait object:

rust
#[handler]
async fn create_todo(req: &mut Request) -> Result<Json<Todo>, ParseError> {
    let payload = req.parse_json::<CreateTodo>().await?;
    Ok(Json(Todo {
        id: 1,
        text: payload.text,
    }))
}

This needs the derive feature on serde, added separately:

bash
cargo add serde --features derive

The failure mode follows from the signature. `parse_json` returns a `ParseError`, and a malformed body and a field of the wrong type both land in that value, as does a body that never arrived. Every handler that accepts input inherits the obligation to decide what the client is told, because the framework hands back a parse failure instead of a partially bound struct. That is workable, but it is per-handler work, and the example shows no mapping for it.

Actix Web and Axum keep middleware a separate type, and that is the whole difference

The closest alternative is Axum, since both build on Tokio and Hyper and both can reach for tower middleware. Axum draws the line differently: a handler is a function from request to response, and anything that wraps a handler is a `tower::Layer` producing a new service. Composing auth, tracing and compression is therefore explicit stack construction rather than a branch of a router.

The consequence is where cross-cutting logic lives. In Axum you can attach a layer to a sub-router and the type system records what ran; in Salvo the same job is a `#[handler]` function on a branch, readable but not statically distinct from an endpoint. Actix Web sits at the other end of the range, with its own runtime and actor model, so choosing it is a runtime decision before it is a middleware decision. Salvo's `examples/` directory covers PostgreSQL through diesel, sea-orm and sqlx, MongoDB, GraphQL, CORS, CSRF and a concurrency limiter, which tells you the integration surface is broad. It does not tell you how those pieces behave against a large request body.

Editorial conclusion

Adopt Salvo if you are writing a small to mid-sized async Rust service and want the routing tree, OpenAPI output and ACME setup in one dependency set. Do not adopt it if your team is standardising on Actix Web or Axum, since the handler-as-middleware design pulls you out of that ecosystem's conventions. Before committing, read the #[handler] macro expansion on docs.rs/salvo and check that your auth layer fits the hoop() signature rather than an Actix Transform.

Frequently asked questions

How do I install Salvo in a Rust project?

Add the crate and the async runtime together with the OpenAPI feature: `cargo add salvo tokio --features salvo/oapi,tokio/macros`. A separate scaffolding CLI is installed with `cargo install salvo-cli` and run as `salvo new my_project`.

Do I need middleware traits to write auth or logging in Salvo?

No. Middleware is written as a handler that receives the response, then attached to a route branch with hoop(), so one function type serves both endpoints and middleware.

How does Salvo generate OpenAPI documentation?

Changing a handler's attribute from `#[handler]` to `#[endpoint]` makes the OpenAPI layer read that signature, and the Quick Start enables the `oapi` feature at install time.

Does Salvo support HTTP/3 by default?

HTTP/3 is opt-in at the listener through a `.quinn(...)` call on the TCP listener, and the workspace manifest pins `salvo-http3` at 0.7.0 while the other crates sit at 1.1.0.

Official sources

  1. License: Apache-2.0
  2. Project website
  3. README
  4. Releases
  5. salvo-rs/salvo on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/salvo-rs-salvo.svg)](https://hysenlabs.com/projects/salvo-rs-salvo)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/salvo-rs-salvo.svg)](https://hysenlabs.com/projects/salvo-rs-salvo)

Was this useful?