actix/actix-web
GitHub: actix/actix-web
Actix Web 是一个基于 Rust 的高性能、异步 Web 框架,旨在以极低的资源消耗提供顶级的 HTTP 服务性能。
Stars: 24498 | Forks: 1856
Actix Web
Actix Web 是一个强大、务实且极快的 Rust web 框架
[](https://crates.io/crates/actix-web)
[](https://docs.rs/actix-web/4.13.0)


[](https://deps.rs/crate/actix-web/4.13.0)
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
[](https://codecov.io/gh/actix/actix-web)

[](https://discord.gg/NWpN5mmg3x)
## 特性
- 支持 _HTTP/1.x_ 和 _HTTP/2_
- 流式处理和管道化
- 强大的[请求路由](https://actix.rs/docs/url-dispatch/),支持可选宏
- 完全兼容 [Tokio](https://tokio.rs)
- Keep-alive 和慢请求处理
- 客户端/服务器 [WebSockets](https://actix.rs/docs/websockets/) 支持
- 透明的内容压缩/解压缩 (br, gzip, deflate, zstd)
- Multipart 流
- 静态资源
- 使用 OpenSSL 或 Rustls 的 SSL 支持
- 中间件([Logger, Session, CORS 等](https://actix.rs/docs/middleware/))
- 集成 [`awc` HTTP 客户端](https://docs.rs/awc/)
- 运行于稳定版 Rust 1.88+
### 实验性功能
为了加快发布迭代速度,我们将某些功能标记为实验性功能。
这些功能带有 `experimental` 前缀,并且随时可能发生破坏性变更。
请自担风险在生产环境中使用它们。
- `experimental-introspection`:公开用于本地诊断和工具的路由和方法报告辅助程序。参见
[`examples/introspection.rs`](examples/introspection.rs) 和
[`examples/introspection_multi_servers.rs`](examples/introspection_multi_servers.rs)。
## 文档
- [网站与用户指南](https://actix.rs)
- [示例仓库](https://github.com/actix/examples)
- [API 文档](https://docs.rs/actix-web)
- [API 文档](https://actix.rs/actix-web/actix_web)
## 示例
依赖项:
```
[dependencies]
actix-web = "4"
```
代码:
```
use actix_web::{get, web, App, HttpServer, Responder};
#[get("/hello/{name}")]
async fn greet(name: web::Path
) -> impl Responder {
format!("Hello {name}!")
}
#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().service(greet)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
```
### 更多示例
- [Hello World](https://github.com/actix/examples/tree/main/basics/hello-world)
- [基本设置](https://github.com/actix/examples/tree/main/basics/basics)
- [应用状态](https://github.com/actix/examples/tree/main/basics/state)
- [JSON 处理](https://github.com/actix/examples/tree/main/json/json)
- [Multipart 流](https://github.com/actix/examples/tree/main/forms/multipart)
- [MongoDB 集成](https://github.com/actix/examples/tree/main/databases/mongodb)
- [Diesel 集成](https://github.com/actix/examples/tree/main/databases/diesel)
- [SQLite 集成](https://github.com/actix/examples/tree/main/databases/sqlite)
- [Postgres 集成](https://github.com/actix/examples/tree/main/databases/postgres)
- [Tera 模板](https://github.com/actix/examples/tree/main/templating/tera)
- [Askama 模板](https://github.com/actix/examples/tree/main/templating/askama)
- [使用 Rustls 的 HTTPS](https://github.com/actix/examples/tree/main/https-tls/rustls)
- [使用 OpenSSL 的 HTTPS](https://github.com/actix/examples/tree/main/https-tls/openssl)
- [简单 WebSocket](https://github.com/actix/examples/tree/main/websockets)
- [WebSocket 聊天](https://github.com/actix/examples/tree/main/websockets/chat)
您可以考虑查看[此目录](https://github.com/actix/examples/tree/main)以获取更多示例。
## 基准测试
根据 [TechEmpower Framework Benchmark](https://www.techempower.com/benchmarks/#section=data-r21&test=composite),这是目前可用的最快的 web 框架之一。
## 许可证
本项目根据以下任一许可证授权,您可以任选其一:
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) 或 [http://www.apache.org/licenses/LICENSE-2.0])
- MIT license ([LICENSE-MIT](LICENSE-MIT) 或 [http://opensource.org/licenses/MIT])
## 行为准则
对 `actix/actix-web` 仓库的贡献根据 Contributor Covenant 的条款进行管理。Actix 团队承诺介入以维护该行为准则。标签:Actix, DNS解析, HTTP/2, HTTP服务器, IP 地址批量处理, OpenSSL, RESTful API, Rust, Rustls, TLS/SSL, Tokio, WebSocket, Web框架, 中间件, 依赖分析, 可视化界面, 后端开发, 安全测试工具, 开发库, 开源项目, 异步编程, 提示词优化, 流处理, 系统编程, 网络安全, 网络流量审计, 路由分发, 隐私保护