Axum is a modular, ergonomic web framework built on Tokio and Tower, while Actix-web is a high-performance framework known for its speed and lower-level control. Axum prioritizes developer experience with type-safe routing and middleware composition, whereas Actix-web focuses on raw throughput and explicit state management.
// Axum: Modular and ergonomic
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, Axum!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
// Actix-web: High performance and explicit
use actix_web::{web, App, HttpServer, HttpResponse, Responder};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().route("/", web::get().to(|| async { HttpResponse::Ok().body("Hello, Actix!") }))
})
.bind("127.0.0.1:8080")?
.run()
.await
}