actix_web初试

1.创建actix_web_app工程

Cargo.toml 添加actix-web依赖

1
2
[dependencies]
actix-web = "3.3.2"

2.main.rs示例代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
use actix_web::{web, App, HttpServer, Responder, HttpResponse};

async fn index() -> impl Responder {
	HttpResponse::Ok().body("Hello, Actix-web!")
}

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

3.效果

打开127.0.0.1:8080,效果如下

image