Scaffold Rust web API with Actix-web or Axum
✓Works with OpenClaudeYou are a Rust backend developer. The user wants to scaffold a production-ready web API using either Actix-web or Axum framework.
What to check first
- Run
rustc --versionto verify Rust 1.70+ is installed - Run
cargo --versionto confirm Cargo is available - Decide between Actix-web (mature, high-performance) or Axum (modern, tokio-based, trait-object free)
Steps
- Create a new Cargo project with
cargo new my_api --bin - Add dependencies to
Cargo.toml: chooseactix-web = "4"ORaxum = "0.7", plustokio = { version = "1", features = ["full"] }andserde = { version = "1", features = ["derive"] } - For Actix: set up
#[actix_web::main]macro in main.rs; for Axum: use#[tokio::main] - Define request/response structs using
#[derive(Serialize, Deserialize)]from serde - Create handler functions with correct signatures: Actix uses
HttpRequest+web::Json<T>parameters; Axum usesJson<T>extractors and async return types - Define routes using
web::scope()in Actix orRouter::new().route()builder in Axum - Configure middleware for logging:
middleware::Loggerin Actix,TraceLayerin Axum withtower_http - Bind to address and start server:
HttpServer::new()for Actix oraxum::Server::bind()for Axum
Code
// Axum example (modern approach)
use axum::{
extract::{Json, Path},
http::StatusCode,
routing::{get, post},
Router,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::Mutex;
#[derive(Serialize, Deserialize, Clone, Debug)]
struct Item {
id: u32,
name: String,
description: String,
}
#[derive(Serialize, Deserialize)]
struct CreateItemRequest {
name: String,
description: String,
}
type ItemStore = Arc<Mutex<Vec<Item>>>;
#[tokio::main]
async fn main() {
let store: ItemStore = Arc::new(Mutex::new(vec![]));
let app = Router::new()
.route("/items", post(create_item).get(list_items))
.route("/items/:id", get(get_item).delete(delete_item))
.route("/health", get(health_check))
.with_state(store);
let listener = tokio::net::T
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Rust Skills
Other Claude Code skills in the same category — free to download.
Rust CLI
Build fast CLI applications with Clap in Rust
Rust Testing
Set up Rust unit and integration testing
Rust WASM
Build WebAssembly modules with Rust and wasm-pack
Rust Error Handling
Implement proper error handling with thiserror and anyhow
Rust Async
Implement async programming with Tokio runtime
Rust Serde
Serialize and deserialize data with Serde in Rust
Rust Error Handling Patterns
Build idiomatic error types using thiserror for libraries and anyhow for applications
Rust Async with Tokio
Write async Rust services with Tokio runtime for high-performance I/O
Want a Rust skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.