rocket_health 0.2.0

Drop-in /health route for Rocket APIs with uptime and rolling average latency metrics.
Documentation
# rocket_health

> ๐Ÿ”ง Drop-in `/health` route for [Rocket]https://rocket.rs APIs with uptime and rolling average latency metrics.

[![Crates.io](https://img.shields.io/crates/v/rocket_health.svg)](https://crates.io/crates/rocket_health)
[![Docs.rs](https://docs.rs/rocket_health/badge.svg)](https://docs.rs/rocket_health)
[![CI](https://github.com/juliengriffoul/rocket_health/actions/workflows/build.yml/badge.svg)](https://github.com/juliengriffoul/rocket_health/actions)

---

## โœจ Features

- ๐Ÿš€ Easy integration into any Rocket API
- ๐Ÿ“ˆ Tracks server **uptime**
- โšก Measures **average response latency** (rolling window)
- ๐Ÿ“ค Exposes `/health` route returning structured JSON

Example response:

```json
{
  "status": "ok",
  "uptime_seconds": 432.123,
  "mean_latency_seconds": 0.0054
}
````

---

## ๐Ÿ“ฆ Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
rocket_health = "0.1"
rocket = { version = "0.5", features = ["json"] }
```

---

## ๐Ÿš€ Usage

### Step 1: Mount health route and fairing

```rust
#[macro_use] extern crate rocket;
use rocket_health::mount_health_route;

#[launch]
fn rocket() -> _ {
    let rocket = rocket::build();
    mount_health_route(rocket)
}
```

### Step 2: Start your Rocket app

The `/health` route is now available:

```
GET /health
```

Returns uptime and latency in seconds (float). Latency is computed using a sliding window of the last 100 requests.

---

## ๐Ÿงช Testing

You can unit test the handler or compute test coverage using [`cargo-tarpaulin`](https://github.com/xd009642/tarpaulin):

```sh
cargo install cargo-tarpaulin
cargo tarpaulin --out Html --ignore-tests --line --target-dir tarpaulin-target/ --skip-clean
```