Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware, and testing with tower.
Agentic Workflow: Read -> Reason -> Act (axum)
You are Axum (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for axum
- Domain: Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware, and testing with tower.
- project-setup: Create an Axum project and add dependencies. —
cargo new axum-api
- serve-and-test: Run the server and test routes with tower ServiceExt. —
cargo run
- Check
knowledge and prerequisites: cargo
2. Reason — think for axum
- For
project-setup: Create an Axum project and add dependencies. — decide which checks to run
- For
serve-and-test: Run the server and test routes with tower ServiceExt. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with axum tools
- Tools:
Glob, Grep, Read, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
axum:04a32048
Axum
What this skill does
Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware (CORS/tracing), and route testing with tower.
When to use
- A new Rust REST API with tokio
- Adding extractors, state, or middleware to an existing app
- Fast, compile-time-safe routing
Real commands
cargo new axum-api
cargo add axum tokio --features tokio/full
cargo add serde --features derive
cargo add tower-http --features cors,trace
cargo run
curl -s http://localhost:3000/health
cargo test
cargo clippy -- -D warnings
cargo build --release
Minimal server
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new().route("/health", get(|| async { "ok" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
State + extractors
#[derive(Clone)]
struct Db { pool: String }
let app = Router::new()
.route("/users/:id", get(get_user))
.with_state(Db { pool: "postgres://db".into() });
async fn get_user(State(db): State<Db>, Path(id): Path<u64>) -> String {
format!("user {id} via {}", db.pool)
}
Testing
- Test routers with tower::ServiceExt::oneshot
- Use
cargo test and clippy in CI
Best practices
- Share dependencies via state, not globals
- Use path parameters and typed extractors instead of manual parsing
- Layer CORS via tower-http, not hand-rolled middleware
Capabilities
project-setup
Create an Axum project and add dependencies.
Parameters:
features (string): Cargo features for axum or tower-http
Commands:
cargo new axum-api
cargo add axum tokio --features tokio/full
cargo add serde --features derive
cargo add tower-http --features cors
cargo build
Examples:
- cargo new axum-api && cargo add axum tokio --features tokio/full
- cargo add axum --features multipart,ws
- cargo add tower-http --features trace,cors
serve-and-test
Run the server and test routes with tower ServiceExt.
Parameters:
port (number): Bind port (default 3000)
addr (string): Bind address
Commands:
cargo run
curl -s http://localhost:3000/health
cargo test
cargo clippy -- -D warnings
cargo build --release
Examples:
References
1---2name: "axum"3description: "Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware, and testing with tower. Use when working with project setup, serve and test, api or when the user mentions project setup, serve and test, api."4license: "MIT"5compatibility: "Requires cargo. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/axum8 author: Kdesk9 version: 2.0.010 category: api11allowed-tools: "Glob Grep Read Bash(cargo:*) Bash(curl:*)"12---1314Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware, and testing with tower.1516## Agentic Workflow: Read -> Reason -> Act (axum)1718You are **Axum** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — api context for `axum`21- Domain: Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware, and testing with tower.22- **project-setup**: Create an Axum project and add dependencies. — `cargo new axum-api`23- **serve-and-test**: Run the server and test routes with tower ServiceExt. — `cargo run`24- Check `knowledge` and `prerequisites: cargo`2526### 2. Reason — think for `axum`27- For `project-setup`: Create an Axum project and add dependencies. — decide which checks to run28- For `serve-and-test`: Run the server and test routes with tower ServiceExt. — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `axum` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `axum:04a32048`3536# Axum3738## What this skill does3940Builds HTTP APIs in Rust with Axum: routing, extractors, shared state, middleware (CORS/tracing), and route testing with tower.4142## When to use4344- A new Rust REST API with tokio45- Adding extractors, state, or middleware to an existing app46- Fast, compile-time-safe routing4748## Real commands4950```bash51cargo new axum-api52cargo add axum tokio --features tokio/full53cargo add serde --features derive54cargo add tower-http --features cors,trace5556cargo run57curl -s http://localhost:3000/health5859cargo test60cargo clippy -- -D warnings61cargo build --release62```6364## Minimal server6566```rust67use axum::{routing::get, Router};6869#[tokio::main]70async fn main() {71 let app = Router::new().route("/health", get(|| async { "ok" }));72 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();73 axum::serve(listener, app).await.unwrap();74}75```7677## State + extractors7879```rust80#[derive(Clone)]81struct Db { pool: String }8283let app = Router::new()84 .route("/users/:id", get(get_user))85 .with_state(Db { pool: "postgres://db".into() });8687async fn get_user(State(db): State<Db>, Path(id): Path<u64>) -> String {88 format!("user {id} via {}", db.pool)89}90```9192## Testing9394- Test routers with tower::ServiceExt::oneshot95- Use `cargo test` and clippy in CI9697## Best practices9899- Share dependencies via state, not globals100- Use path parameters and typed extractors instead of manual parsing101- Layer CORS via tower-http, not hand-rolled middleware102103## Capabilities104105### project-setup106Create an Axum project and add dependencies.107108**Parameters:**109- `features` (string): Cargo features for axum or tower-http110111**Commands:**112- `cargo new axum-api`113- `cargo add axum tokio --features tokio/full`114- `cargo add serde --features derive`115- `cargo add tower-http --features cors`116- `cargo build`117118**Examples:**119- cargo new axum-api && cargo add axum tokio --features tokio/full120- cargo add axum --features multipart,ws121- cargo add tower-http --features trace,cors122123### serve-and-test124Run the server and test routes with tower ServiceExt.125126**Parameters:**127- `port` (number): Bind port (default 3000)128- `addr` (string): Bind address129130**Commands:**131- `cargo run`132- `curl -s http://localhost:3000/health`133- `cargo test`134- `cargo clippy -- -D warnings`135- `cargo build --release`136137**Examples:**138- cargo run && curl -s http://localhost:3000/health139- cargo test -- --nocapture140- cargo clippy --all-targets -- -D warnings141142## References143- [Axum Docs (docs.rs)](https://docs.rs/axum/latest/axum/)144- [Axum README](https://github.com/tokio-rs/axum)145- [tower-http](https://docs.rs/tower-http)