### actix-web
$ cargo new my_web_app
$ cd my_web_app
[dependencies] actix-web = "4"
main.rs
use actix_web::{web, App, HttpResponse, HttpServer, Responder}; async fn greet() -> impl Responder { HttpResponse::Ok().body("Hello, world!") } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(||{ App::new() .route("/", web::get().to(greet)) }) .bind("127.0.0.1:8080")? .run() .await }
$ curl 127.0.0.1:8080
Hello, world!
ほう
### Rocket
$ cargo new rocket_web_app
$ cd rocket_web_app
$ rustup override set nightly
#[macro_use] extern crate rocket; #[get("/")] fn index() -> &'static str { "Hello, world!" } #[launch] fn rocket() -> _ { rocket::build().mount("/", routes![index]) }
$ cargo run
Compiling rocket_web_app v0.1.0 (/home/vagrant/dev/rust/rocket_web_app)
error[E0463]: can’t find crate for `rocket`
–> src/main.rs:1:14
|
1 | #[macro_use] extern crate rocket;
| ^^^^^^^^^^^^^^^^^^^^ can’t find crate
….
rocketの方は色々エラーが出るので、少し触った感じではactix-webの方が使いやすそう..