Narsi Bhati Logo

Command Palette

Search for a command to run...

Hello World in Rust with Axum

Jan 03, 2026

A minimal Hello World web server using Rust and the Axum framework.

Axum is a fast, ergonomic web framework for Rust built on Tokio (async runtime) and Tower (middleware). In this post we’ll build a minimal “Hello, World!” server you can run in a few minutes.

Setup

Create a new project and add the dependencies:

cargo new hello-axum
cd hello-axum

In Cargo.toml:

[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }

The server

In src/main.rs:

use axum::{routing::get, Router};
 
#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(handler));
 
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}
 
async fn handler() -> &'static str {
    "Hello, World!"
}

Run it

cargo run

Open http://localhost:3000 and you should see Hello, World!.

What’s going on

  • Router – Defines routes; here we attach a single GET / to handler.
  • handler – An async function that returns a string; Axum sends it as text/plain with status 200.
  • tokio::main – Runs the async runtime so main can await.

From here you can add more routes, JSON with axum::Json, and middleware from the Tower ecosystem.