hyper & tower: The HTTP and Middleware Under axum
Learn the two libraries every Rust web framework is built on: hyper, the low-level HTTP implementation, and tower, the universal async Service abstraction. The Service trait, Layers and middleware composition, the tower-http toolbox, and exactly how axum is a tower Service over hyper. The bottom of the Rust web stack, made visible.
- What hyper & tower Are hyper is Rust's low-level HTTP library; tower is the Service abstraction for async request-to-response plus composable Layers. Together they're the foundation axum is built on.
- hyper: The HTTP Library How hyper actually speaks HTTP on a socket: the http crate's Request and Response, body types and the Body trait, and serving a connection with TokioIo and service_fn.
- The Service Trait tower::Service is the universal async request-to-response shape: call does the work, poll_ready signals readiness for backpressure. Why it's generic, why it composes, and service_fn as the easy path.
- Layers & Middleware Middleware is a Service that wraps another Service; a tower::Layer is the factory that does the wrapping. Compose layers cleanly with ServiceBuilder, and learn the ordering rule that trips everyone up.
- The tower-http Toolbox tower-http is a box of ready-made Layers — tracing, CORS, compression, timeouts, body limits, static files — that snap onto any HTTP tower service. The concrete payoff of the Service/Layer abstraction.
- How axum Uses Them The payoff: axum's Router is a tower Service, axum::serve is hyper, .layer is a tower Layer, and extractors are typed sugar over hyper's raw Request/Response. Every axum concept maps to a root.
- Where to Go Next The payoff: the same Service and Layer model that runs an axum server also runs gRPC with tonic and outbound clients with retry, timeout, and load balancing. One mental model for the whole Rust web stack.