简介
https://github.com/actix/actix-web
https://actix.rs/
https://crates.io/crates/actix-web
https://docs.rs/actix-rt/1.0.0/actix_rt/
https://docs.rs/actix/0.9.0/actix/
https://docs.rs/actix-web-actors/2.0.0/actix_web_actors/index.html
另外一个 Rust web 框架:
https://github.com/SergioBenitez/Rocket
web 框架性能测试排行:
https://www.techempower.com/benchmarks/
最简单的一个例子
Cargo.toml:
| [dependencies]
actix-web = "2.0"
actix-rt = "1.0.0"
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 | use actix_web::{web, App, HttpRequest, HttpServer, Responder};
async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
.bind("127.0.0.1:8002")?
.run()
.await
}
|