axum 是Tokio官方推出的Web框架

  • 官方文档:https://docs.rs/axum/latest/axum

  • Axum 使用tokio线程池,方便与其他支持tokio多线程/异步的第三方库集成

  • Axum 的中间件是直接使用 tower 的抽象

    • 使用了统一 的 Service 和 Layer 抽象标准,基于 tokio / hyper/ tonic 生态

Hello World!

use axum::{
    routing::get,
    Router,
};

#[tokio::main]
async fn main() {
    // build our application with a single route
    let app = Router::new().route("/", get(|| async { "Hello, World!" }));

    // run it with hyper on localhost:3000
    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}