Rust API
Rule
Keep transport concerns at the edge and domain logic in testable services. Prefer Axum for
greenfield async HTTP APIs when a framework is approved.
Hard Stops
Ask before:
- Choosing/changing framework, routes, schemas, status codes, auth policy, CORS, rate limits,
or error formats.
- Calling live services, production databases, real secrets, or external identity providers
in tests.
- Adding OpenAPI generators, middleware stacks, validation derive crates, or OpenTelemetry.
- Weakening TLS, auth, tenant isolation, request limits, or audit behavior.
Defaults
- Use Axum with Tokio, Tower, and Tower HTTP for new async APIs when approved.
- Use typed request/response models with
serde.
- Keep handlers thin: extract, authorize, call service, map result.
- Use typed application state; avoid global state.
- Map domain errors to structured transport errors with stable status codes and response
bodies.
- Add request size limits, timeouts, and graceful shutdown for services.
- Use
tracing spans at request and important I/O boundaries.
- Use
utoipa for OpenAPI only when schema generation is explicitly needed.
Testing
Use in-process service tests with tower::ServiceExt or framework-established patterns.
Avoid real network ports where possible. Assert status, headers when meaningful, JSON shape,
validation errors, auth hooks, and side effects through isolated stores.
Workflow
- Define route, method, schema, status codes, errors, auth, and compatibility needs.
- Choose Axum or existing project framework based on approved scope.
- Implement thin handlers over services/state.
- Add middleware only for concrete needs: request ID, tracing, auth, CORS, compression,
timeouts, body limits, or recovery.
- Add tests for success, validation, auth, errors, and cancellation.
- Run targeted tests, full tests, Clippy, and
just check.
Antipatterns
- Business logic embedded in handlers.
- Returning raw internal errors to clients.
- Creating Tokio runtimes inside libraries or handlers.
- Logging request bodies or auth headers.
- OpenAPI schemas that are not tested against real responses.
Completion
Report API contract, framework/dependency choices, validation and error behavior, auth
assumptions, tests, and validation results.
Source: nyquistwilder/personal-pi — distributed by TomeVault.
1---2name: rust-api3description: Greenfield Rust HTTP API workflow for Axum or project-selected frameworks, handlers, middleware, validation, status codes, structured errors, auth hooks, OpenAPI concerns, Tower services, and service tests. Use when this capability is needed.4---56# Rust API78## Rule910Keep transport concerns at the edge and domain logic in testable services. Prefer Axum for11greenfield async HTTP APIs when a framework is approved.1213## Hard Stops1415Ask before:1617- Choosing/changing framework, routes, schemas, status codes, auth policy, CORS, rate limits,18 or error formats.19- Calling live services, production databases, real secrets, or external identity providers20 in tests.21- Adding OpenAPI generators, middleware stacks, validation derive crates, or OpenTelemetry.22- Weakening TLS, auth, tenant isolation, request limits, or audit behavior.2324## Defaults2526- Use Axum with Tokio, Tower, and Tower HTTP for new async APIs when approved.27- Use typed request/response models with `serde`.28- Keep handlers thin: extract, authorize, call service, map result.29- Use typed application state; avoid global state.30- Map domain errors to structured transport errors with stable status codes and response31 bodies.32- Add request size limits, timeouts, and graceful shutdown for services.33- Use `tracing` spans at request and important I/O boundaries.34- Use `utoipa` for OpenAPI only when schema generation is explicitly needed.3536## Testing3738Use in-process service tests with `tower::ServiceExt` or framework-established patterns.39Avoid real network ports where possible. Assert status, headers when meaningful, JSON shape,40validation errors, auth hooks, and side effects through isolated stores.4142## Workflow43441. Define route, method, schema, status codes, errors, auth, and compatibility needs.452. Choose Axum or existing project framework based on approved scope.463. Implement thin handlers over services/state.474. Add middleware only for concrete needs: request ID, tracing, auth, CORS, compression,48 timeouts, body limits, or recovery.495. Add tests for success, validation, auth, errors, and cancellation.506. Run targeted tests, full tests, Clippy, and `just check`.5152## Antipatterns5354- Business logic embedded in handlers.55- Returning raw internal errors to clients.56- Creating Tokio runtimes inside libraries or handlers.57- Logging request bodies or auth headers.58- OpenAPI schemas that are not tested against real responses.5960## Completion6162Report API contract, framework/dependency choices, validation and error behavior, auth63assumptions, tests, and validation results.6465---66> Source: [nyquistwilder/personal-pi](https://github.com/nyquistwilder/personal-pi) — distributed by [TomeVault](https://tomevault.io).67<!-- tomevault:4.0:skill_md:2026-06-16 -->