agentleFS
leroyguillaumeleroyguillaume/claude/rust-http-conventions/SKILL.md

rust-http-conventions

Skill7 starsChanged 2 days agoMITView on GitHub

Rust HTTP stack: `axum` + `aide`, `schemars`, `validator`. TRIGGER when: editing a Rust HTTP handler, router, extractor or DTO; adding an endpoint to a Rust service; wiring `axum`, `aide`, `schemars`, Scalar or `validator`; OpenAPI from Rust; user asks about multipart, body limits or input validation in Rust. SKIP when: no HTTP surface (`rust-conventions`), or language-agnostic API design (`api-conventions`).

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never expose an HTTP API without aide: no bare axum::Router for an API, no hand-written OpenAPI.

    line 47
  2. Very specific:

    Never use a web framework other than axum.

    line 49
  3. Very specific:

    Never hand-roll input validation (bespoke validate() methods returning Result<(), String>, ad-hoc field checks scattered through handlers) …

    line 50
  4. Very specific:

    Call aide::generate::extract_schemas(true) once before building the router so types are emitted as reusable #/components/schemas $refs.

    line 63
  5. Very specific:

    Document path/query parameters with named structs (Path<GamePath>, not Path<Uuid> / Path<(Uuid, Uuid)>).

    line 67
  6. Very specific:

    Add an example to a request/response schema with #[schemars(extend("example" = serde_json::json!({...})))] — the auto-generated placeholder …

    line 91
  7. Very specific:

    Keep infrastructure endpoints (liveness/health probe, metrics, …) out of the OpenAPI document: register them with plain route(...), not …

    line 94
  8. Distinctive:

    If the API has authentication, document it in OpenAPI: register the scheme once

    line 98

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust HTTP/API conventions

Applies on top of rust-conventions (language and tooling) and api-conventions (wire contract: dedicated DTOs, camelCase JSON, pagination, tagged operations, the OpenAPI document at /openapi.json rendered by Scalar at /docs). This skill is the Rust-specific stack and its wiring.

Always:

  • Every HTTP server / API uses the same stack, always: axum + aide — no exceptions. Never expose a bare axum::Router for an API: build the router with aide's ApiRouter (drop-in for axum), and document every endpoint.
  • Generate the OpenAPI document with aide (its ApiRouter drop-in for axum) and schemars (derive JsonSchema on every request/response DTO). api-conventions says where it is served and what renders it.
  • Validate deserialised input (request DTOs, config payloads, …) with the validator crate (derive API), not hand-rolled checks. Put #[derive(Validate)] on the input struct, use the built-in field validators (length, range, email, url, nested, …) where they fit, and #[validate(custom(function = path::to::fn))] for domain-specific rules — the function takes &T and returns Result<(), validator::ValidationError>, and in validator ≥ 0.19 function is a bare path, not a string literal. Call value.validate()? at the edge (e.g. the axum handler) and provide a From<validator::ValidationErrors> for your error type so it maps to a 422. Keep cross-entity / database-backed checks (e.g. "this id must belong to that parent") in the repository/service layer; validator covers field-level shape only. Add it with cargo add validator --features derive.
  • Pass the graceful-shutdown future from rust-conventions to axum::serve(..).with_graceful_shutdown(shutdown_signal()).

Never:

  • Never expose an HTTP API without aide: no bare axum::Router for an API, no hand-written OpenAPI. Every endpoint is documented.
  • Never use a web framework other than axum.
  • Never hand-roll input validation (bespoke validate() methods returning Result<(), String>, ad-hoc field checks scattered through handlers) when the validator derive can express it, and never pull in another validation crate when validator fits.

aide wiring, learned the hard way

Most of these surface as a cryptic OperationHandler bound failure, or as an endpoint that compiles and documents nothing.

  • Enable the aide features axum, axum-json, macros — the base axum feature does not make axum::Json an OperationInput/Output, so without axum-json no JSON handler satisfies OperationHandler.
  • Call aide::generate::extract_schemas(true) once before building the router so types are emitted as reusable #/components/schemas $refs.
  • Implement aide::OperationOutput (a no-op type Inner = () is enough) for your error type so Result<_, AppError> is a valid documented return.
  • Document path/query parameters with named structs (Path<GamePath>, not Path<Uuid> / Path<(Uuid, Uuid)>); aide derives parameter names from the struct fields, so bare/tuple extractors document no parameters. Give those structs #[serde(rename_all = "camelCase")] so job_id binds and documents as the {jobId} the route declares.
  • The (StatusCode, Json<T>) tuple documents no response; declare the success status of creates explicitly with post_with(handler, |op| op.response::<201, Json<XxxResponse>>()).
  • Pin the schemars version aide re-exports (the version aide depends on: cargo tree -i schemars) and add its chrono04 / uuid1 features for DateTime/Uuid fields.
  • OperationInput for Query<T> is behind aide's axum-query feature. A handler taking Query<_> fails the OperationHandler bound (cryptically) until you enable it, so the feature set is usually axum, axum-json, axum-query, macros. A custom extractor likewise needs a (no-op) impl OperationInput.
  • For file uploads, take axum's Multipart extractor (multipart/form-data, one field per file → supports several files in one request). Enable axum-multipart on aide: it provides Multipart's OperationInput (else the OperationHandler bound fails) and turns on axum's multipart feature itself. axum's default request body limit is only 2 MiB, far too small for PDFs — raise it per route with post_with(handler, …).layer(DefaultBodyLimit::max(N)) (aide's ApiMethodRouter has .layer, so the limit stays scoped to the upload route rather than the whole API).
  • Add an example to a request/response schema with #[schemars(extend("example" = serde_json::json!({...})))] — the auto-generated placeholder ("string", null) reads poorly in Scalar.
  • Keep infrastructure endpoints (liveness/health probe, metrics, …) out of the OpenAPI document: register them with plain route(...), not api_route(...). The documented surface is the product API, not the ops plumbing.
  • If the API has authentication, document it in OpenAPI: register the scheme once
    router.finish_api_with(&mut api, |t| {
        t.security_scheme(
            "BearerAuth",
            aide::openapi::SecurityScheme::Http {
                scheme: "bearer".into(),
                bearer_format: Some("JWT".into()),
                description: None,
                extensions: Default::default(),
            },
        )
    })
    and require it per protected operation with op.security_requirement("BearerAuth"). Leave public operations (login, public reads) without a requirement. This makes Scalar show the lock icon and a token input.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.