altair-server
Axum + tower-http convenience layer with sensible defaults and graceful shutdown.
Part of the altair-rs workspace.
Add to your project
The underlying axum, tower, and tower-http are re-exported — you don't need to add them separately.
Quick start
use Server;
use get;
async
Server::run() binds the listener, applies the default middleware stack, and serves until SIGINT (Ctrl-C) or SIGTERM. Returns Ok(()) after graceful shutdown completes.
What you get out of the box
- Tracing per request via
tower_http::trace::TraceLayer. Ifaltair-otelis initialized in the same process, those spans flow to OTLP automatically. - Request ID (
x-request-id) propagation — generated if missing, echoed in response. - Per-request timeout (default 30s, configurable).
GET /healthendpoint returning200 OK(customizable path + body).- Graceful shutdown on SIGINT/SIGTERM via
tokio::signal.
Routes
.route(), .merge(), and .nest() delegate directly to axum:
use Server;
use Router;
use get;
# async
# async
# async
Configuration
use Server;
use Duration;
# async
Custom CORS
use Server;
use CorsLayer;
use Method;
# async
Custom health response
use Server;
use Json;
use json;
# async
Graceful shutdown patterns
Server::run() installs SIGINT (Ctrl-C) and SIGTERM (Unix) handlers automatically.
For tests or orchestration scenarios where you need programmatic shutdown:
use Server;
use oneshot;
use Duration;
# async
Error reference
| Variant | When |
|---|---|
Error::Bind |
TCP listener couldn't bind (port in use, permission denied, ...) |
Error::Io |
I/O error during the serve loop (rare, from tokio/hyper internals) |
Error::Configuration |
Builder rejected a configuration value (e.g. invalid bind address) |