If you're learning Rust and want to build APIs, Axum is one of the best frameworks to start with.
In this tutorial, we'll build a simple CRUD API (Create, Read, Update, Delete) using:
✅ Axum
✅ In-memory storage (no database)
✅ Beginner-friendly concepts
What We Will Build
A simple User API with these endpoints:
Method Route Description
POST /users Create a user
GET /users Get all users
GET /user/:id Get a single user
PUT /user/:id Update a user
DELETE /user/:id Delete a user
Step 1: Setup Dependencies
Add this to your Cargo.toml :
[dependencies] axum = "0.7" tokio = { version = "1" , features = [ "full" ] } serde = { version = "1" , features = [ "derive" ] } serde_json = "1"
Enter fullscreen mode
Exit fullscreen mode
Step 2: Define Our Data
#[derive(Debug, Serialize, Deserialize, Clone)] struct User { id : u32 , name : String , email : String , }
#[derive(Deserialize)] struct CreateUser { name : String , email : String , }
Enter fullscreen mode
Exit fullscreen mode
User → the stored…