axum-web-service
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Architects, builds, and optimizes production Rust web APIs using Axum, Tokio async runtime, Tower middlewares, type-safe state extractors, and SQLx connection pools.
In this repository108 other files it gives its agents.
- AGENTS.mdAGENTS.md
- everything-gemini-maintainerSkill
- adversarial-fuzz-generatorSkill
- agent-evalsSkill
- ai-first-engineeringSkill
- alloydb-omni-vectorSkill
- apache-kafka-streamsSkill
- api-craftsmanSkill
- architecture-designerSkill
- argon-3d-game-engineSkill
- argon-3d-scene-architectSkill
- argon-procedural-asset-generatorSkill
- argon-visual-critique-loopSkill
- argo-workflowsSkill
- autonomous-incident-healerSkill
- bigquery-vector-searchSkill
- browser-qa-testerSkill
- chromadb-vector-storeSkill
- cilium-ebpf-networkingSkill
- clickhouse-analyticsSkill
- cloud-deploy-canarySkill
- cloudflare-r2-object-storageSkill
- cloudflare-workersSkill
- cloud-run-agentsSkill
- context-cachingSkill
- context-distillation-compressorSkill
- context-warmerSkill
- continuous-learningSkill
- cost-oracle-finopsSkill
- cross-repo-swarm-syncSkill
- cve-remediation-orchestratorSkill
- database-architectSkill
- dataproc-spark-analyticsSkill
- dbt-transformationSkill
- debezium-cdcSkill
- devops-pipelineSkill
- distributed-rate-limitingSkill
- docker-compose-orchestratorSkill
- duckdb-local-olapSkill
- dynamic-thinking-allocationSkill
- ebpf-microvm-sandboxSkill
- ebpf-sandbox-enforcerSkill
- elephant-goldfish-modelSkill
- envoy-ai-gatewaySkill
- ephemeral-swarm-orchestratorSkill
- fastapi-productionSkill
- fullstack-nextjsSkill
- game-audio-synthesizerSkill
- game-studioSkill
- gemini-function-callingSkill
- gemini-groundingSkill
- gemini-live-audio-transcriberSkill
- gemini-live-multimodalSkill
- gemini-live-screen-visionSkill
- gemini-multimodalSkill
- genetic-prompt-cross-pollinatorSkill
- git-craftsmanSkill
- github-opsSkill
- google-axSkill
- google-flow-orchestratorSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 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.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 68
Use Axum's compile-time extractors to ensure payload and state invariants before handler execution:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Axum Web Service Architecture (Rust)
This skill guides engineering microservices with Axum—the high-throughput, ergonomic Rust web framework built on top of Tokio, Tower, and Hyper.
⚡ Core Patterns
1. Application State & Router Composition (main.rs)
use axum::{
extract::{Path, State},
http::StatusCode,
response::IntoResponse,
routing::{get, post},
Json, Router,
};
use sqlx::PgPool;
use std::{net::SocketAddr, sync::Arc};
use tower_http::{cors::CorsLayer, trace::TraceLayer};
#[derive(Clone)]
pub struct AppState {
pub db: PgPool,
pub redis: redis::aio::ConnectionManager,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let db_pool = PgPool::connect(&std::env::var("DATABASE_URL")?).await?;
let redis_client = redis::Client::open(std::env::var("REDIS_URL")?)?;
let redis_mgr = redis_client.get_tokio_connection_manager().await?;
let shared_state = Arc::new(AppState {
db: db_pool,
redis: redis_mgr,
});
let app = Router::new()
.route("/healthz", get(|| async { StatusCode::OK }))
.nest("/api/v1", api_v1_router())
.layer(TraceLayer::new_for_http())
.layer(CorsLayer::permissive())
.with_state(shared_state);
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
let listener = tokio::net::TcpListener::bind(addr).await?;
tracing::info!("Listening on {}", addr);
axum::serve(listener, app).await?;
Ok(())
}2. Type-Safe Handlers with SQLx (handlers/users.rs)
Use Axum's compile-time extractors to ensure payload and state invariants before handler execution:
use axum::{
extract::{Path, State},
Json,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use crate::{AppState, error::AppError};
#[derive(Deserialize)]
pub struct CreateUserPayload {
pub username: String,
pub email: String,
}
#[derive(Serialize)]
pub struct UserResponse {
pub id: i64,
pub username: String,
pub email: String,
}
pub async fn create_user(
State(state): State<Arc<AppState>>,
Json(payload): Json<CreateUserPayload>,
) -> Result<Json<UserResponse>, AppError> {
// Compile-time verified query via SQLx
let user = sqlx::query_as!(
UserResponse,
r#"
INSERT INTO users (username, email)
VALUES ($1, $2)
RETURNING id, username, email
"#,
payload.username,
payload.email
)
.fetch_one(&state.db)
.await?;
Ok(Json(user))
}3. Unified RFC 7807 Error Envelope (error.rs)
Transform any internal database or validation failure into clean, typed JSON responses using IntoResponse:
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
use serde_json::json;
#[derive(thiserror::Error, Debug)]
pub enum AppError {
#[error("Database error: {0}")]
Database(#[from] sqlx::Error),
#[error("Resource not found")]
NotFound,
#[error("Validation failed: {0}")]
Validation(String),
}
impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, detail) = match self {
AppError::NotFound => (StatusCode::NOT_FOUND, "The requested resource does not exist.".to_string()),
AppError::Validation(msg) => (StatusCode::BAD_REQUEST, msg),
AppError::Database(err) => {
tracing::error!("Internal DB error: {:?}", err);
(StatusCode::INTERNAL_SERVER_ERROR, "An internal server error occurred.".to_string())
}
};
let body = Json(json!({
"type": "https://errors.example.com",
"title": status.canonical_reason().unwrap_or("Error"),
"status": status.as_u16(),
"detail": detail
}));
(status, body).into_response()
}
}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
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.

