# How do I create a minimal web server with axum?
Source: https://ruststudio.org/community/t/158/how-do-i-create-a-minimal-web-server-with-axum
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: rustc 1.93.0, axum 0.8.9, tokio 1.54.1, Windows 11; cargo run and curl.exe against the running program
Category: Guides | Kind: Guide | Tags: axum, web, getting-started, tokio | Views: 0

## Short answer
Create a binary crate, add axum and tokio to Cargo.toml, build a Router with one route, bind a TcpListener and pass both to axum::serve. Run it with cargo run and open the address in a browser or curl. The whole program is a few lines long.

## Answer
## What you will build
A program that answers `GET /` with the text `hello from axum` on `127.0.0.1:3001`.

## Before you start
- Rust installed (`rustc --version` prints a version).

## Steps
### 1. Create the crate and add the dependencies
```text
cargo new hello-web
cd hello-web
```

```toml title=Cargo.toml
[dependencies]
axum = "0.8.9"
tokio = { version = "1.54.1", features = ["full"] }
```

### 2. Write the server
`#[tokio::main]` starts the async runtime. `Router` maps a path and method to a handler; the closure `|| async { ... }` is a handler that returns a string.

```rust title=src/main.rs
use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "hello from axum" }));
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3001").await.unwrap();
    println!("listening on {}", listener.local_addr().unwrap());
    axum::serve(listener, app).await.unwrap();
}
```

### 3. Run it and call it
```text
cargo run
```

In a second terminal, `curl -i http://127.0.0.1:3001/` printed:

```text
HTTP/1.1 200 OK
content-type: text/plain; charset=utf-8
content-length: 15
date: Sat, 05 Dec 2026 09:02:16 GMT

hello from axum
```

The first terminal printed `listening on 127.0.0.1:3001`. Stop the server with Ctrl+C.

## Check that it works
Open `http://127.0.0.1:3001/` in a browser: the page shows `hello from axum`. Any other path answers 404 with an empty body.

## Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| the program panics at `bind(...).unwrap()` with an error about the address being in use (the wording differs by system) | another program, or a second copy of this one, holds port 3001 | stop it or bind a different port |
| the browser cannot connect from another machine | `127.0.0.1` accepts only local connections | bind `0.0.0.0:3001` when outside access is intended |

## Going further
- Next: how routing, path parameters and nested routers work (thread "How do I define routes, path parameters and nested routers in axum?").
- Read the port and address from configuration instead of writing them in the code.

## Related questions
### Why does axum need tokio?
`axum::serve` and the handlers are async, and something has to run them. `tokio` is that runtime; `#[tokio::main]` sets it up around `main`.

## Sources
- axum, `serve`: https://docs.rs/axum/0.8.9/axum/fn.serve.html (read 2026-12-05)
- The Rust Book, installation and Cargo: https://doc.rust-lang.org/book/ch01-00-getting-started.html
