servlet 1.1.0

A small application runtime with an explicit operational contract
Documentation
# Servlet

[![CI](https://github.com/chimlet/servlet/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/chimlet/servlet/actions/workflows/ci.yml)

Servlet runs Axum routes and supervises background tasks on Tokio. Tasks and readiness checks gate startup. On shutdown, it drains in-flight requests.

```rust
use servlet::{App, Result};

#[servlet::main]
async fn main() -> Result<()> {
    App::new("hello-servlet")
        .get("/", async || "hello\n")
        .run()
        .await
}
```

Pass an existing router to `App::http`.

## Run the example

Create a project with Rust 1.97 or later.

```sh
cargo new hello-servlet
cd hello-servlet
cargo add servlet@1.1.0
```

Save the example as `src/main.rs` and start it with `cargo run`. Call the route from another terminal.

```console
$ curl http://127.0.0.1:8080/
hello
```

## 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.

## 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`.

## Optional features

| Feature | Adds |
| --- | --- |
| `client` | Pooled HTTP requests with deadlines and body limits |
| `postgres` | SQLx connection pools with readiness checks |
| `otel` | OpenTelemetry trace export over OTLP/HTTP |
| `recourse` | Typed HTTP errors with request IDs |

Open the API reference from the repository root.

```sh
cargo doc --locked -p servlet \
  --all-features --no-deps --open
```

## Dependency versions

Servlet 1.1.0 declares these requirements in its manifest. The release lockfile records the exact versions tested. [Cargo.lock at v1.1.0](https://github.com/chimlet/servlet/blob/v1.1.0/Cargo.lock)

| 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` |
| `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` |

**Applications can update Tokio independently.** Servlet allows Tokio `>=1.53.3, <2.0.0`. Run `cargo update -p tokio` in your application to update its lockfile within the project's dependency requirements. `servlet::ecosystem::tokio` re-exports the Tokio types Servlet uses. [Cargo dependency resolution](https://doc.rust-lang.org/cargo/reference/resolver.html#version-requirements)

Servlet updates its workspace lockfile with Cargo and validates the new resolution in CI. Changing a published requirement takes a new Servlet release. SQLx is pinned for pool recycling, and the macro crate is pinned to the matching Servlet release.

Licensed under [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE).