Agent skill
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.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/design/rust-backend-api-caioniehues-dotfiles
SKILL.md
<essential_principles>
- Validation at the Edge - Validate all external input immediately.
- Code-First OpenAPI - Documentation lives in the code via derive macros.
- Schema as Contract - ToSchema-derived types define the API contract. </essential_principles>
use validator::Validate;
#[derive(Debug, Deserialize, Validate, ToSchema)]
pub struct CreateUserRequest {
#[validate(email)]
#[schema(example = "[email protected]")]
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()?;
// ...
}
#[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)
}
<success_criteria>
- 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 </success_criteria>
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?