Quick start
Create a project with Rust 1.97 or later.
Save this as src/main.rs.
use ;
async
Start the server with cargo run, then call it from another terminal.
$ curl http://127.0.0.1:8080/
hello
Use App::http to pass in an existing Axum router.
Roles and components
Use App::with_role to choose what a process runs. For a binary with several named components, register factories with Components::component and pick one with Components::select.
| Role | Application HTTP | App::worker |
App::service |
|---|---|---|---|
All (default) |
Yes | Yes | Yes |
Api |
Yes | No | Yes |
Worker |
No | Yes | Yes |
Services and workers start after setup and call ctx.ready() when ready. The configured admin listener stays available in every role. Use AppConfig::from_env_for_role when loading settings explicitly.
Register worker_with_state and service_with_state before setup or state. A selected task receives a clone of the initialized state.
use ;
async
For recurring work, WorkerContext::poll handles readiness, waits, shutdown, and optional progress tracking.
Health and metrics
The app listens on 127.0.0.1:8080 by default. Set SERVLET_BIND to change its address.
Set SERVLET_ADMIN_BIND=127.0.0.1:9090 for a separate admin listener. It serves /live, /ready, and Prometheus metrics at /metrics.
Use App::configure to override selected settings after SERVLET_* variables load.
let app = new.configure;
Use App::config to supply the entire configuration and bypass automatic environment loading. For explicit environment loading, use AppConfig::from_env_for_role.
SetupContext::status gives application routes read-only lifecycle and readiness information. For a finite command, use App::run_once to run setup and await managed cleanup without opening listeners.
Optional features
| Feature | Adds |
|---|---|
client |
Pooled HTTP requests with deadlines and body limits |
postgres |
SQLx connection pools, readiness checks, and managed listeners |
otel |
OpenTelemetry trace export over OTLP/HTTP |
recourse |
Typed HTTP errors with request IDs |
Open the API reference from the repository root.
Test an HTTP app
Let the OS choose a free port and await startup before sending requests.
let mut config = default;
config.bind = "127.0.0.1:0".parse?;
let running = new
.config
.get
.start
.await?;
let address = running.local_addr.expect;
// Send test requests to address.
running.handle.shutdown;
running.wait.await?;
Dependency versions
Servlet 1.2.0 declares these requirements in its manifest. The release lockfile records the exact versions tested.
| Crate | Cargo requirement | Tested version |
|---|---|---|
axum |
0.8 |
0.8.9 |
tokio |
1.53.3 |
1.54.1 |
tokio-util |
0.7 |
0.7.20 |
hyper |
1 |
1.12.0 |
hyper-util |
0.1 |
0.1.21 |
tower |
0.5 |
0.5.3 |
tracing |
0.1 |
0.1.44 |
tracing-subscriber |
0.3 |
0.3.23 |
prometheus |
0.14 |
0.14.0 |
reqwest |
0.13 |
0.13.5 |
sqlx |
=0.9.1 |
0.9.1 |
tokio-postgres |
0.7.18 |
0.7.19 |
tokio-postgres-rustls |
0.14 |
0.14.0 |
opentelemetry |
0.33 |
0.33.1 |
recourse |
=0.0.1-rc.3 |
0.0.1-rc.3 |
recourse-axum |
=0.0.1-rc.3 |
0.0.1-rc.3 |
zlid |
=0.0.1-rc.4 |
0.0.1-rc.4 |
License
MIT or Apache 2.0.