home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Serve A Hello, World Web Page In Rust With axum

Creating a rust server app with a single hard coded web page doesn't require much code at all.

September 2023
Code
[package]
name = "axum_hello_world"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = {version = "1", features = ["full"] }
axum = "0.6"
Code
use axum::response::IntoResponse;
use axum::routing::get;
use axum::{response::Html, Router};
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    let index_route = Router::new().route("/", get(index_handler));
    let addr = SocketAddr::from(([127, 0, 0, 1], 8181));
    axum::Server::bind(&addr)
        .serve(index_route.into_make_service())
        .await
        .unwrap();
}

async fn index_handler() -> impl IntoResponse {
    println!("Got request for /");
    Html("Hello, world")
}

Notes

═══ § ═══

Footnotes And References