use actix_web::{
    get, web, App, HttpServer, Responder, HttpRequest, HttpResponse,
};

#[get("/{id}/{name}/index.html")]
async fn index(info: web::Path<(u32, String)>) -> impl Responder {
    format!("Hello {}! id:{}", info.1, info.0)
}

#[get("/name")]
async fn index_name() -> impl Responder {
    format!("Hello name!\n")
}

async fn index2(req: HttpRequest) -> HttpResponse {
    println!("{:?}", req);
    HttpResponse::Ok()
        .content_type("text/plain")
        .body("Welcome!\n")
}

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    println!("Listen at: http://127.0.0.1:8080/");
    
    HttpServer::new(|| App::new()
            .service(index)
            .service(index_name)
            .service(web::resource("/").to(index2))
        )
        .bind("127.0.0.1:8080")?
        .run()
        .await
}
