Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

actix_in_a_fn.rs

// Imports
use actix_web::{App, HttpResponse, HttpServer, web};

// Main function, literally all in one func, this is pretty cool for the lazy!
// There are 2 closures here for actix_web v4 in this example!
#[actix_web::main]
async fn main() {
    println!("Hello, world!");
    HttpServer::new(|| {
        App::new()
            .route("/", web::get().to(|| async {
                HttpResponse::Ok().body("hi, from main() lol!".to_string())
            }))
    })
        .bind("0.0.0.0:80")
        .unwrap()
        .run()
        .await
        .unwrap()
}