manutej/luxor-claude-marketplace/axum-web-framework

Claude Code and agent skill by manutej/luxor-claude-marketplace

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Complete guide for Axum web framework including routing, extractors, middleware, state management, error handling, and production deployment

Install

npx vskill@latest install manutej/luxor-claude-marketplace/axum-web-framework

SKILL.md

Axum Web Framework

A comprehensive skill for building production-ready web applications and APIs using Axum, the ergonomic and modular Rust web framework built on Tokio and Tower. Master routing, extractors, middleware, state management, error handling, and deployment patterns.

When to Use This Skill

Use this skill when:

  • Building REST APIs with Rust and async/await
  • Creating high-performance web services with type safety
  • Developing microservices with Tokio ecosystem integration
  • Implementing WebSocket servers or Server-Sent Events (SSE)
  • Building GraphQL APIs with Rust backend
  • Creating middleware-heavy applications requiring Tower integration
  • Developing production-ready web applications requiring robust error handling
  • Building systems requiring fine-grained control over HTTP request/response handling
  • Implementing authentication, authorization, and security middleware
  • Creating real-time web applications with async Rust
  • Developing APIs requiring request validation and transformation
  • Building web services with complex routing and nested routers
  • Implementing rate limiting, timeout, and backpressure handling
  • Creating web applications requiring custom extractors and response types

Core Concepts

Axum Architecture Philosophy

Axum is built on three fundamental pillars:

  1. Tower Services: Everything in Axum is built on Tower's Service trait, providing composability and middleware integration
  2. Type-Safe Extractors: Request data extraction is compile-time checked, eliminating runtime parsing errors
  3. Minimal Boilerplate: Ergonomic APIs that reduce ceremony while maintaining explicitness
The Router

The Router is the central building block in Axum. It maps HTTP requests to handlers based on path and method.

Key Properties:

  • Routes are matched in the order they're defined
  • Routers can be nested for modular organization
  • Middleware can be applied at router, route, or method level
  • Generic over state type for flexible state management
  • Implements Tower's Service trait for composability

Router Creation:

rust
use axum::{Router, routing::get};
let app = Router::new()
.route("/", get(handler))
.route("/users/:id", get(get_user))
.route("/posts", get(list_posts).post(create_post));
Handlers

Handlers are async functions that process requests and return responses. Axum supports multiple handler signatures through its powerful type system.

Handler Requirements:

  • Must be async functions
  • Can extract data from requests using extractors
  • Must return types implementing IntoResponse
  • Can have up to 16 parameters (all must be extractors)

Common Handler Patterns:

rust
// Simple handler
async fn handler() -> &'static str {
"Hello, World!"
}
// Handler with path parameter
async fn get_user(Path(user_id): Path<u32>) -> String {
format!("User ID: {}", user_id)
}
// Handler with multiple extractors
async fn create_user(
State(state): State<AppState>,
Json(payload): Json<CreateUser>,
) -> Result<Json<User>, StatusCode> {
// Implementation
}
Extractors

Extractors are types that implement FromRequest or FromRequestParts, allowing type-safe extraction of data from requests.

Built-in Extractors:

  1. Path - Extract path parameters
  2. Query - Extract query string parameters
  3. Json - Parse JSON request body
  4. Form - Parse form-encoded request body
  5. State - Access shared application state
  6. Extension - Access request extensions
  7. Headers - Access request headers
  8. Method - Get HTTP method
  9. Uri - Get request URI
  10. Request - Get full request
  11. Bytes - Raw request body as bytes
  12. String - Request body as UTF-8 string
  13. Multipart - Handle multipart/form-data

Extractor Ordering:

  • Extractors that consume the request body must come last
  • Multiple body extractors in one handler will cause compilation errors
  • State and other non-body extractors can be in any order
Responses

Any type implementing IntoResponse can be returned from handlers. Axum provides many built-in implementations.

Built-in Response Types:

  • String, &'static str - Text responses
  • Json<T> - JSON responses
  • Html<String> - HTML responses
  • StatusCode - Status-only responses
  • (StatusCode, T) - Status with body
  • (Parts, T) - Custom headers with body
  • Response - Full control over response
  • Result<T, E> - Error handling (where E: IntoResponse)
State Management

Axum uses the State extractor to share data across handlers. State must implement Clone and is typically wrapped in Arc for shared ownership.

State Patterns:

  1. Simple State:
rust
#[derive(Clone)]
struct AppState {
api_key: String,
}
let app = Router::new()
.route("/", get(handler))
.with_state(AppState {
api_key: "secret".to_string(),
});
  1. Shared State with Arc:
rust
#[derive(Clone)]
struct AppState {
db_pool: Arc<DatabasePool>,
cache: Arc<RwLock<Cache>>,
}
  1. Multiple State Types:
rust
// Define separate state types for different router sections
let api_router: Router<ApiState> = Router::new()
.route("/api/data", get(api_handler));
let app_router: Router<AppState> = Router::new()
.route("/app", get(app_handler));
// Combine with final state
let app = Router::new()
.nest("/", app_router.with_state(app_state))
.nest("/", api_router.with_state(api_state));
Middleware

Middleware in Axum comes from Tower and provides request/response transformation, logging, authentication, and more.

Middleware Categories:

  1. Tower Middleware - From tower and tower-http crates
  2. Custom Middleware - Using middleware::from_fn
  3. Service Middleware - Implementing Tower's Service trait
  4. Layer Pattern - Using Tower's Layer for composability

Middleware Application Order:

  • Applied with .layer() executes bottom-to-top (wrapping previous layers)
  • Applied with ServiceBuilder executes top-to-bottom (more intuitive)
  • Middleware on Router::layer runs after routing
  • Middleware around Router (using Layer::layer) runs before routing
Error Handling

Axum's error handling is built on the IntoResponse trait, allowing custom error types to be converted to HTTP responses.

Error Handling Strategies:

  1. Result Types:
rust
async fn handler() -> Result<Json<Data>, StatusCode> {
// Returns 200 OK or error status code
}
  1. Custom Error Types:
rust
enum AppError {
Database(sqlx::Error),
NotFound,
Unauthorized,
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
// Convert to HTTP response
}
}
  1. HandleErrorLayer:
rust
use axum::error_handling::HandleErrorLayer;
let app = Router::new()
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(handle_error))
.layer(TimeoutLayer::new(Duration::from_secs(30)))
);
Tower Integration

Axum is built on Tower, enabling powerful middleware composition and service abstraction.

Key Tower Concepts:

  1. Service Trait - Asynchronous request processing
  2. Layer Trait - Middleware factory pattern
  3. ServiceBuilder - Ergonomic middleware composition
  4. Timeout - Request timeout handling
  5. RateLimit - Request rate limiting
  6. LoadShed - Backpressure management
  7. Buffer - Request buffering

Routing

Basic Routing

Routes map HTTP methods and paths to handlers:

rust
use axum::{
Router,
routing::{get, post, put, delete, patch},
};
let app = Router::new()
.route("/", get(root))
.route("/users", get(list_users).post(create_user))
.route("/users/:id", get(get_user).put(update_user).delete(delete_user))
.route("/posts/:id/comments", get(get_comments).post(add_comment));
Path Parameters

Extract dynamic segments from paths:

rust
use axum::extract::Path;
use serde::Deserialize;
// Single parameter
async fn get_user(Path(user_id): Path<u32>) -> String {
format!("User {}", user_id)
}
// Multiple parameters
#[derive(Deserialize)]
struct PostPath {
user_id: u32,
post_id: u32,
}
async fn get_post(Path(params): Path<PostPath>) -> String {
format!("User {} Post {}", params.user_id, params.post_id)
}
// Using tuple for multiple params
async fn get_comment(
Path((post_id, comment_id)): Path<(u32, u32)>
) -> String {
format!("Post {} Comment {}", post_id, comment_id)
}
Wildcard Routes

Capture remaining path segments:

rust
// Captures all remaining path
async fn handler(Path(path): Path<String>) -> String {
format!("Captured path: {}", path)
}
let app = Router::new()
.route("/{*key}", get(handler));
// GET /foo/bar/baz -> path = "foo/bar/baz"

Important: Nested routers strip matched prefixes, but wildcard routes retain the full URI.

Nested Routers

Organize routes into modules using router nesting:

rust
use axum::{Router, routing::get};
fn api_routes() -> Router {
Router::new()
.route("/users", get(list_users))
.route("/users/:id", get(get_user))
.route("/posts", get(list_posts))
}
fn admin_routes() -> Router {
Router::new()
.route("/dashboard", get(dashboard))
.route("/settings", get(settings))
}
let app = Router::new()
.nest("/api", api_routes())
.nest("/admin", admin_routes())
.route("/", get(root));

Nesting Behavior:

  • Matched prefix is stripped from URI before passing to nested router
  • Handlers in nested routers only see path relative to nest point
  • Fallback handlers are inherited from parent if not defined in child
  • Middleware can be applied before or after nesting
Fallback Handlers

Handle unmatched routes:

rust
use axum::{http::StatusCode, handler::Handler};
async fn fallback() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "Not Found")
}
let app = Router::new()
.route("/", get(handler))
.fallback(fallback);

Fallback Inheritance:

rust
async fn api_fallback() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "API endpoint not found")
}
let api = Router::new()
.route("/users", get(list_users))
.fallback(api_fallback);
let app = Router::new()
.nest("/api", api)
.fallback(fallback); // Used for non-/api routes
Method Routing

Handle multiple HTTP methods on the same route:

rust
use axum::routing::{get, post, MethodRouter};
// Multiple methods on one route
let app = Router::new()
.route("/users", get(list_users).post(create_user));
// Different handlers per method
let app = Router::new()
.route("/resource",
get(get_resource)
.post(create_resource)
.put(update_resource)
.delete(delete_resource)
.patch(patch_resource)
);

Extractors Deep Dive

Path Extractor

Extract typed path parameters:

rust
use axum::extract::Path;
use serde::Deserialize;
// Simple extraction
async fn user_by_id(Path(id): Path<u32>) -> String {
format!("User {}", id)
}
// Complex extraction
#[derive(Deserialize)]
struct Params {
org: String,
repo: String,
issue: u32,
}
async fn github_issue(Path(params): Path<Params>) -> String {
format!("{}/{} issue #{}", params.org, params.repo, params.issue)
}
let app = Router::new()
.route("/users/:id", get(user_by_id))
.route("/repos/:org/:repo/issues/:issue", get(github_issue));
Query Extractor

Extract query string parameters:

rust
use axum::extract::Query;
use serde::Deserialize;
#[derive(Deserialize)]
struct Pagination {
page: Option<u32>,
per_page: Option<u32>,
}
async fn list_users(Query(pagination): Query<Pagination>) -> String {
let page = pagination.page.unwrap_or(1);
let per_page = pagination.per_page.unwrap_or(20);
format!("Page {} with {} items", page, per_page)
}

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
49
Repository forks
12
7-day trend score
20

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 5 Apr 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/manutej/luxor-claude-marketplace/axum-web-framework/badge)](https://verified-skill.com/skills/manutej/luxor-claude-marketplace/axum-web-framework)

Something wrong with this skill or its page? Tell us.