Rust Axum 高性能 Web API 实战use axum::{routing::get, Router, Json}; use serde_json::json; use std::net::SocketAddr; async fn hello() -> Json<serde_json::Value> { Json(json!({"message": "hello"})) } #[tokio::main] async fn main() { let app = Router::new().route("/api/hello", get(hello)); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); axum::Server::bind(&addr).serve(app.into_make_service()).await.unwrap(); } 要点使用 `#[tokio::main]` 与非阻塞 I/O结合 Tower 中间件进行限流与日志扩展总结Axum 在 Rust 生态中提供简洁高性能的 Web 框架,适合现代微服务与网关场景。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.548916s