Hello World Server
Technical Review Approved
Updated: 2026-09-13
Actix Web 4.x
RS Rust 1.75+
VERIFIED
The simplest possible Actix Web server demonstrating the Tokio runtime macro and handler basics.
Actix Web: 4.x
Rust: 1.75+
What You Will Build
A minimal web server that responds with 'Hello World!' to any GET request on the root path.
What You Will Learn
- How to start an HttpServer
- How to define an App factory
- How to create a simple string responder
Project Setup
src/main.rs
Edition 2024
1cargo new hello-world2cd hello-world
Dependencies (`Cargo.toml`)
src/main.rs
Edition 2024
1[dependencies]2actix-web = "4"
Complete Code
src/main.rs
Click highlighted lines to inspect mechanics1use actix_web::{get, App, HttpServer, Responder};
2
3#[get("/")]
4async fn hello() -> impl Responder {
5 "Hello World!"
6}
7
8#[actix_web::main]
9async fn main() -> std::io::Result<()> {
10 println!("Server starting on http://127.0.0.1:8080");
11 HttpServer::new(|| {
12 App::new().service(hello)
13 })
14 .bind(("127.0.0.1", 8080))?
15 .run()
16 .await
17}
Line 3 - 6
Expected Result
src/main.rs
Edition 2024
1$ curl http://127.0.0.1:80802Hello World!
How It Works
The `HttpServer` binds to a local port and starts a multi-threaded asynchronous runtime. It builds an `App` factory that registers the `hello` service. When a request hits `/`, the `hello` async function is executed by one of the worker threads.
Try It Yourself
EASYExercise
Change the response text to 'Hello Actix!'.
MEDIUMExercise
Add a second route at `/ping` that returns `pong`.
Create a new async function with `#[get("/ping")]` and chain `.service(ping)` on `App::new()`.