rust-backend-api

Provides API design patterns for Rust backends including request validation with validator, OpenAPI documentation with utoipa, and SwaggerUI integration. Use when building REST APIs with Axum, adding request validation, generating OpenAPI specs, or setting up API documentation.

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026⬇️2downloads

When & Why to Use This Skill

This Claude skill streamlines Rust backend development by providing production-ready API design patterns. It integrates the Axum framework with the 'validator' crate for type-safe request validation and 'utoipa' for automated OpenAPI documentation and SwaggerUI integration. It ensures that developers can build secure, well-documented, and standardized RESTful services with minimal boilerplate.

Use Cases

  • Rapid REST API Development: Quickly scaffold Axum-based web services with built-in validation and documentation structures.
  • Automated OpenAPI Documentation: Generate real-time OpenAPI specifications and interactive SwaggerUI directly from Rust code using derive macros.
  • Type-Safe Request Validation: Implement 'validation at the edge' to ensure all incoming API data is sanitized and conforms to defined constraints before reaching business logic.
  • API Contract Standardization: Use schema-derived types to maintain a consistent contract between backend implementation and frontend/client consumption.
namerust-backend-api
descriptionProvides API design patterns for Rust backends including request validation with validator, OpenAPI documentation with utoipa, and SwaggerUI integration. Use when building REST APIs with Axum, adding request validation, generating OpenAPI specs, or setting up API documentation.
Enable production-quality REST API development with type-safe request validation, automatic OpenAPI documentation, and interactive API exploration. 1. **Validation at the Edge** - Validate all external input immediately. 2. **Code-First OpenAPI** - Documentation lives in the code via derive macros. 3. **Schema as Contract** - ToSchema-derived types define the API contract. **Request Validation**
use validator::Validate;

#[derive(Debug, Deserialize, Validate, ToSchema)]
pub struct CreateUserRequest {
    #[validate(email)]
    #[schema(example = "user@example.com")]
    pub email: String,

    #[validate(length(min = 8, max = 64))]
    pub password: String,

    #[validate(length(min = 1, max = 100))]
    #[schema(example = "Jane Doe")]
    pub name: String,
}

pub async fn create_user(
    State(state): State<AppState>,
    Json(req): Json<CreateUserRequest>,
) -> Result<Json<UserResponse>, AppError> {
    req.validate()?;
    // ...
}
**OpenAPI with utoipa**
#[utoipa::path(
    post,
    path = "/users",
    tag = "users",
    request_body = CreateUserRequest,
    responses(
        (status = 201, description = "User created", body = UserResponse),
        (status = 400, description = "Validation error")
    )
)]
pub async fn create_user(/* ... */) { }

#[derive(OpenApi)]
#[openapi(
    info(title = "My API", version = "1.0.0"),
    tags((name = "users", description = "User management"))
)]
struct ApiDoc;

pub fn create_router(state: AppState) -> Router {
    let (router, api) = OpenApiRouter::with_openapi(ApiDoc::openapi())
        .routes(routes!(create_user))
        .split_for_parts();

    router
        .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", api))
        .with_state(state)
}
- [ ] All request types derive Validate with constraints - [ ] Validation errors return 400 with field-specific messages - [ ] All endpoints have #[utoipa::path] documentation - [ ] SwaggerUI accessible and shows all endpoints - [ ] OpenAPI spec includes security schemes if using auth