Axum is a Rust web framework for building HTTP services on the Tokio async runtime. Its small, type-safe core is mostly macro-free and provides routing, extractors, responses, error handling, and integration with Tower. It uses hyper for HTTP/1 and HTTP/2. section 9.1 section 9.11
Use axum::Router to associate request paths and methods with handlers, supply state, and combine routes with service layers. A basic service does not require detailed Tower knowledge; deeper customization benefits from learning Tower. section 9.7 section 9.1
Declare API routes
A router can expose health checks and nest versioned endpoints: `Router::new().route("/alive", get(|| async { "ok" })).route("/ready", get(ping)).nest("/v1", Router::new().route("/todos", get(todo_list).post(todo_create)).route("/todos/:id", get(todo_read).put(todo_update).delete(todo_delete)))`. The `/todos/:id` route maps multiple methods to handlers for the same path. This syntax follows the example’s axum 0.6.18 dependency. section 9.7 section 9.4
Listing 9.11 API service router from src/router.rs
pub async fn create_router(
dbpool: sqlx::Pool<sqlx::Sqlite>, #1
) -> axum::Router {
use crate::api::{
ping, todo_create, todo_delete, todo_list, todo_read, todo_update,
};
use axum::{routing::get, Router};
use tower_http::cors::{Any, CorsLayer};
use tower_http::trace::TraceLayer;
Router::new()
.route("/alive", get(|| async { "ok" })) #2
.route("/ready", get(ping)) #3
.nest(
"/v1", #4
Router::new()
.route("/todos", get(todo_list).post(todo_create)) #5
.route(
"/todos/:id",
get(todo_read).put(todo_update)
.delete(todo_delete),
), #6
)
.with_state(dbpool) #7
.layer(CorsLayer::new().allow_methods(Any)
.allow_origin(Any)) #8
.layer(TraceLayer::new_for_http()) #9
}
Inspect the router example for its handler imports, database pool argument, health checks, and nested routes. section 9.7
Start a project with `cargo new api-server` and add the framework with `cargo add axum`. Add other crates as needed: the example uses Tokio for the runtime, SQLx for database access, and tower-http for tracing and CORS. Dependencies can be changed as the service evolves. section 9.4
Table 9.3 API service dependencies (view table figure)
Review the example service’s dependency roles and feature selections. section 9.4
Keep service design separate from framework setup: choose a data model, state management, response formats, and architecture, then configure tracing and metrics for production. Consult axum’s documentation for framework features beyond the basic router. section 9.11 section 9.1 section 9.7

