Axum is a Rust web framework built by the Tokio team, the same group behind Rust's dominant async runtime. It ranks around #26 among web frameworks at roughly 2.8% usage share. It's known for type-safe routing and "extractors" that pull typed data straight out of requests, extremely high raw performance, and tight integration with Tokio โ making it a popular pick for Rust developers building high-throughput APIs and microservices.
Axum builds a router by mapping paths to async handler functions, with extractors like Path pulling typed values straight out of the URL.
use axum::{routing::get, Router, extract::Path};
async fn hello() -> &'static str {
"Hello, Axum!"
}
async fn greet(Path(name): Path<String>) -> String {
format!("Hello, {}!", name)
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(hello))
.route("/greet/:name", get(greet));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Create a new Rust binary project with Cargo, then add Axum and Tokio as dependencies.
# create a new Rust project
cargo new my_api
cd my_api
# add dependencies
cargo add axum tokio --features tokio/full
# run it
cargo run