This repository compares Rust web frameworks by implementing the same small API in each of them. A larger sample then shows what a more realistic API looks like, including a database, validation, error handling, and tests.
The samples started out as the demo code for Rainer Stropek's talk Building Web APIs with Rust - State of the Union at Eurorust 2022 and BASTA 2023 (slides). The code has since been updated to current Rust and framework versions, so details may differ from the slides.
| Sample | Framework | What to look for |
|---|---|---|
todo-axum |
Axum | Macro-free routing, extractors, and Tower middleware |
todo-actix-web |
Actix Web | Routing with and without macros, responders, and ResponseError |
todo-rocket |
Rocket | Attribute macros, request guards, and derived responders |
todo-warp |
Warp | Composable filters and rejections |
hero-manager-axum |
Axum and SQLx | Postgres access, validation, problem details, graceful shutdown, and handler tests with mocks |
The four todo samples expose the same API and share their business logic through todo-logic, so the code in each sample is only what is specific to its framework.
- Rust 1.94 or later
- just (optional, for the commands below)
- Docker and sqlx-cli for
hero-manager-axum
Pick axum, actix-web, rocket, or warp:
just run axumEach todo sample listens on port 3000 and keeps its data in memory. requests.http contains example requests for the REST Client extension for VS Code.
All samples log with tracing. Set RUST_LOG to change the log filter:
RUST_LOG=debug just run warpRun these commands in the hero-manager-axum folder:
just start-pgjust create-dbjust apply-migrationsjust runThe API listens on port 4000. The connection string comes from .env, and requests.http contains example requests. The credentials in .env are for the local demo database only.
just checkjust testThe tests do not need a database because the handlers are tested against a mocked repository.