Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

axum-web-framework

БесплатноБез исполняемых скриптовНе проверен

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

manutejот manutej★ 64 звезды на GitHub18 установок в других каталогах

Об этом скилле

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:

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:

// 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:
#[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:
#[derive(Clone)]
struct AppSta
Полный SKILL.md на GitHub

Установить axum-web-framework в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

EXAMPLES.mdREADME.md

FAQ

Что делает скилл axum-web-framework?

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

Как установить скилл axum-web-framework?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл axum-web-framework запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить axum-web-framework с