One small step for Rustaceans, one happy big step for me

Yes, I am a noob. But a very happy noob at the moment. I just started with browser access, and with the help of google, book and some experiments, I have build my first Rust-website. I do know it is laughable simple, but that is not the point obviously. The point is, I have opened it in my browser and it works!

But I would like to know, is my first step a good one, can someone comment on it to give me more/better direction? At this point I can produce some text in the browser. Next steps I will be looking for are some input, some graphics, well, let’s not get carried away :slight_smile: Would anyone like to comment on this bit:

use actix_web::{web, App, HttpServer, Responder};

async fn index() -> impl Responder {
    format!("Hello world!")
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .route("/", web::get().to(index))
    })
    .bind("0.0.0.0:8080")?
    .run()
    .await
}

Don't diminish your accomplishments. You built a web server. 99.9% of human kind will never do that. You are on your journey and it is just as magnificent as that of somebody that has programmed web servers for 30 years.

This looks very much like a standard (albeit small :slightly_smiling_face:) actix-web project. This is only personal preference, but I like to use guards instead of web::get().to(function), maybe you do, too:

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

#[get("/")]
async fn index() -> impl Responder {
    format!("Hello world!")
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().service(index)
    })
    .bind("0.0.0.0:8080")?
    .run()
    .await
}

Will be interesting to see where you go next with that. Web development IMO is super fun and a very rewarding learning experience. Come back here to URLO if you have any questions or get stuck.

4 Likes

Thanks!