Updated Jun 23, 2026

hyper & tower: The HTTP and Middleware Under axum

Underneath axum — and a lot of the Rust networking world — sit two libraries most people never learn directly: hyper, a fast, correct, low-level HTTP implementation, and tower, an abstraction for "an async function from a request to a response" that makes middleware composable across the whole ecosystem. This is the deepest roots guide in the Rust set. You'll rarely write hyper or tower by hand, but understanding them demystifies a stack of things at once: what a Service is, why axum middleware is a tower::Layer, how tower-http gives you tracing/CORS/timeouts for free, and what axum::serve is really doing.

The mental model is one trait and one wrapper. tower::Service is the universal shape: given a request, asynchronously produce a response (plus a readiness check for backpressure). Everything — a whole axum app, a single endpoint, a database client, a rate limiter — can be a Service. A Layer is a function that wraps one Service to make another (that's middleware). hyper, meanwhile, is what actually speaks HTTP on the socket and calls your top-level Service for each request. Hold "a Service turns a request into a response, a Layer wraps a Service, and hyper drives the whole thing over the network," and the Rust web stack lays itself out flat.

📝 This is the deepest roots guide — it assumes Rust (traits, generics, asyncRust From Zero) and the runtime beneath it (Tokio). It's most rewarding after you've used axum, so the pieces have somewhere to land. Examples run as plain Rust programs.

How to read this

Read in order — it builds from hyper's HTTP server up through the Service trait, Layers, and tower-http, then maps the whole thing back onto axum. Phases carry difficulty badges.

The phases

  1. What hyper & tower Are 🟢 — the HTTP library and the Service abstraction, and where they sit in the stack.
  2. hyper: The HTTP Library 🟡 — Request/Response, a bare hyper server, and what it hands your code.
  3. The Service Trait 🔴 — poll_ready + call, the universal "async request → response," and why it's everywhere.
  4. Layers & Middleware 🔴 — tower::Layer, ServiceBuilder, and composing middleware as wrapped services.
  5. The tower-http Toolbox 🟡 — tracing, CORS, compression, and timeouts as reusable layers.
  6. How axum Uses Them 🟢 — axum's Router as a Service over hyper, with your layers wrapped around it.
  7. Where to Go Next 🟢 — applying this to gRPC (tonic), clients, and the rest of the tower ecosystem.

The throughline: a Service turns a request into a response, a Layer wraps a Service (that's middleware), and hyper drives it over the socket. axum is a Service you assembled.


Phase 1: What hyper & tower Are →