actix/actix-web:Actix Web 是一个功能强大、实用且速度极快的 Rust 网络框架。


根据TechEmpower 框架基准测试, Actix Web是最快的 Web 框架之一 ,暂时排名第5名,超过java的vert.x(内置Netty)和akka
特点:

  • 支持HTTP/1.x和HTTP/2
  • 流媒体和流水线
  • 保持活动和缓慢的请求处理
  • 客户端/服务器WebSockets支持
  • 透明内容压缩/解压(br、gzip、deflate、zstd)
  • 强大的请求路由
  • 多部分流
  • 静态资源
  • 使用 OpenSSL 或 Rustls 的 SSL 支持
  • 中间件(记录器、会话、CORS 等
  • 包括一个异步HTTP 客户端
  • 在稳定的 Rust 1.52+ 上运行

依赖:
[dependencies]
actix-web = "3"

代码:

use actix_web::{get, web, App, HttpServer, Responder};

#[get("/{id}/{name}/index.html")]
async fn index(web::Path((id, name)): web::Path<(u32, String)>) -> impl Responder {
    format!(
"Hello {}! id:{}", name, id)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(index))
        .bind(
"127.0.0.1:8080")?
        .run()
        .await
}