Skip to content

Commit 1b4ac50

Browse files
committed
Update README.md
1 parent 5141d88 commit 1b4ac50

1 file changed

Lines changed: 126 additions & 79 deletions

File tree

README.md

Lines changed: 126 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# RustAPI
55

6-
**Rust Speed. Python Simplicity. AI Efficiency.**
6+
A high-performance, ergonomic web framework for Rust with native AI/LLM support.
77

88
[![Crates.io](https://img.shields.io/crates/v/rustapi-rs.svg)](https://crates.io/crates/rustapi-rs)
99
[![Docs](https://img.shields.io/badge/docs-cookbook-brightgreen)](docs/cookbook/src/SUMMARY.md)
@@ -13,68 +13,126 @@
1313

1414
---
1515

16-
## ⚡ Why RustAPI?
16+
## Overview
1717

18-
**Most Rust frameworks force you to choose: Speed (Actix) OR Ergonomics (Axum).**
19-
RustAPI gives you **both**.
18+
RustAPI is a Rust web framework built on **hyper 1.x** and **tokio**, designed for minimal boilerplate while retaining full control over performance. It uses a **facade architecture** (`rustapi-rs`) that shields user code from internal crate changes, keeping the public API stable as internals evolve.
2019

21-
We built the framework we wanted: **FastAPI's developer experience** backed by **Rust's raw performance**.
22-
No boilerplate. No fighting the borrow checker for simple handlers. Just code that flies.
20+
Key design goals:
21+
- **Ergonomic handler signatures** inspired by FastAPI and Axum
22+
- **Native TOON format** for token-efficient LLM responses
23+
- **Auto-discovery** of routes via procedural macros and link-time registration
24+
- **Three-tier request execution** (ultra fast / fast / full) to minimize overhead
2325

24-
## 🧠 The Killer Feature: AI-First Architecture
26+
## What Sets RustAPI Apart
2527

26-
**Problem:** Standard JSON APIs are verbose and expensive for Large Language Models (LLMs).
27-
**Solution:** RustAPI natively supports **TOON (Token-Oriented Object Notation)**.
28+
### Three-Tier Request Execution
2829

29-
Top-tier LLMs (Claude, GPT-4o) charge by the token. RustAPI's TOON format reduces response token counts by **50-58%** compared to standard JSON.
30+
Unlike other Rust frameworks that always run the full middleware chain, RustAPI dynamically selects the cheapest execution path per request:
3031

31-
* **💰 Save 50% on API Costs**: Half the tokens, same data.
32-
* **🌊 Zero-Latency Streaming**: Built for real-time AI agents.
33-
* **🔌 MCP-Ready**: Out-of-the-box support for Model Context Protocol.
32+
| Path | When | Overhead |
33+
|:-----|:-----|:---------|
34+
| **Ultra Fast** | No middleware, no interceptors | Zero Arc cloning, direct handler call |
35+
| **Fast** | Interceptors only, no middleware layers | Interceptor functions only |
36+
| **Full** | Middleware layers present | Complete `LayerStack` execution |
3437

35-
> "RustAPI isn't just a web server; it's the native language of your AI agents."
38+
This means a simple `GET /health` endpoint with no middleware runs at near-zero overhead, while other endpoints on the same server can use JWT, CORS, and rate limiting through the full path.
3639

37-
## 🔄 Time-Travel Debugging (NEW in v0.1.300)
40+
### Facade Architecture with Contract Enforcement
3841

39-
**Production debugging shouldn't be a nightmare.** RustAPI's Replay system records and replays HTTP requests with surgical precision.
42+
User code imports only from `rustapi-rs`. Internal crates (`rustapi-core`, `rustapi-macros`, etc.) can be refactored freely without breaking user code. The public API surface is tracked via committed `cargo public-api` snapshots, and CI enforces labeling rules (`breaking` / `feature`) on any PR that changes them.
43+
44+
### Link-Time Auto-Discovery
45+
46+
Routes annotated with `#[rustapi_rs::get("/...")]` are registered to a `linkme` distributed slice at link time — no manual route registration or inventory macros needed. `RustApi::auto()` collects them and builds a `BTreeMap`-ordered radix tree router via `matchit`.
47+
48+
### TOON: Token-Oriented Object Notation
49+
50+
A compact serialization format that reduces token counts by **50-58%** compared to JSON. `Toon<T>` is a drop-in replacement for `Json<T>`. `LlmResponse<T>` performs automatic content negotiation based on `Accept` headers and adds headers like `X-Token-Count-JSON`, `X-Token-Count-TOON`, and `X-Token-Savings` for observability.
51+
52+
### Built-in Resilience Primitives
53+
54+
RustAPI ships circuit breaker and retry middleware as first-class features, not third-party crate bolt-ons:
55+
56+
- **Circuit Breaker** (`CircuitBreakerLayer`): Fault tolerance with open/half-open/closed states
57+
- **Retry** with exponential backoff
58+
- **Rate Limiting** (IP-based, per-route)
59+
- **Body Limit** with configurable max size (default 1 MB)
60+
61+
### Environment-Aware Error Masking
62+
63+
All error responses include a unique `error_id` (`err_{uuid}`) for log correlation. In production (`RUSTAPI_ENV=production`), 5xx error details are automatically masked to `"An internal error occurred"` while validation errors (4xx) pass through intact.
64+
65+
### Request Replay & Time-Travel Debugging
66+
67+
Record and replay HTTP request/response pairs for production debugging:
4068

4169
```rust
42-
// 1. Enable replay recording in production
4370
RustApi::new()
4471
.layer(ReplayLayer::new(store, config))
4572
.run("0.0.0.0:8080").await;
73+
```
4674

47-
// 2. Replay ANY request from the CLI
48-
$ cargo rustapi replay list
49-
$ cargo rustapi replay run <id> --target http://localhost:8080
50-
$ cargo rustapi replay diff <id> --target http://staging
75+
```sh
76+
cargo rustapi replay list
77+
cargo rustapi replay run <id> --target http://localhost:8080
78+
cargo rustapi replay diff <id> --target http://staging
5179
```
5280

53-
**What makes it special:**
54-
* 🎬 **Zero-Code Recording**: Middleware automatically captures request/response pairs
55-
* 🔐 **Security First**: Sensitive headers redacted, bearer auth required, disabled by default
56-
* 💾 **Flexible Storage**: In-memory (dev) or filesystem (production) with TTL cleanup
57-
* 🧪 **Integration Testing**: `ReplayClient` for programmatic test automation
58-
* 🕵️ **Root Cause Analysis**: Replay exact production failures in local environment
81+
- Middleware-based recording; no application code changes
82+
- Sensitive header redaction; disabled by default
83+
- In-memory (dev) or filesystem (production) storage with TTL
84+
- `ReplayClient` for programmatic test automation
5985

60-
> "Fix production bugs in 5 minutes instead of 5 hours."
86+
### Dual-Stack HTTP/1.1 + HTTP/3
6187

62-
## 🥊 Dare to Compare
88+
Run HTTP/1.1 (TCP) and HTTP/3 (QUIC/UDP) simultaneously on the same server. Enable with the `core-http3` feature flag.
6389

64-
We optimize for **Developer Joy** without sacrificing **Req/Sec**.
90+
### Native OpenAPI 3.1
6591

66-
| Feature | **RustAPI** | Actix-web | Axum | FastAPI (Python) |
67-
|:-------|:-----------:|:---------:|:----:|:----------------:|
68-
| **Performance** | **~92k req/s** | ~105k | ~100k | ~12k |
69-
| **DX (Simplicity)** | 🟢 **High** | 🔴 Low | 🟡 Medium | 🟢 High |
70-
| **Boilerplate** | **Zero** | High | Medium | Zero |
71-
| **AI/LLM Native** |**Yes** | ❌ No | ❌ No | ❌ No |
72-
| **Time-Travel Debug** |**Built-in** | ❌ No | ❌ No | ⚠️ 3rd-party |
73-
| **Stability Logic** | 🛡️ **Facade** | ⚠️ Direct | ⚠️ Direct | ✅ Stable |
92+
`#[derive(Schema)]` generates OpenAPI schemas at compile time. `RustApi::auto()` assembles the full spec with reference integrity validation. Swagger UI is served at `/docs` by default. No external code generators or YAML files needed.
7493

75-
## 🚀 30-Second Start
94+
### Async Validation with Application State
7695

77-
Write your API in 5 lines. It's that simple.
96+
`AsyncValidatedJson<T>` can access application state (e.g., database connections) during validation. The extractor clones `ValidationContext` from request state, enabling rules like "username must be unique" at the validation layer.
97+
98+
### Background Jobs
99+
100+
`rustapi-jobs` provides an async job queue with three backends (Memory, Redis, Postgres), retry with exponential backoff, dead letter queues, and scheduled execution.
101+
102+
### Side-by-Side gRPC + HTTP
103+
104+
`rustapi-grpc` enables running Tonic-based gRPC services alongside RustAPI HTTP handlers in the same process via `run_rustapi_and_grpc`.
105+
106+
### Additional Built-in Capabilities
107+
108+
| Capability | Notes |
109+
|:-----------|:------|
110+
| WebSocket with permessage-deflate | Full compression negotiation via `protocol-ws` |
111+
| Server-Sent Events (SSE) | `SseEvent` with id, event type, retry fields |
112+
| Tera template rendering | `View<T>` response type via `protocol-view` |
113+
| JWT authentication | `AuthUser<T>` extractor + `JwtLayer` |
114+
| CORS | `CorsLayer` with builder pattern |
115+
| `simd-json` acceleration | 2-4x faster JSON parsing via `core-simd-json` feature |
116+
| In-memory `TestClient` | Executes the full middleware stack without network I/O |
117+
| `MockServer` | Expectation-based mock with explicit `verify()` |
118+
| `cargo rustapi new` | Interactive project scaffolding with feature selection |
119+
120+
## Comparison
121+
122+
| Feature | RustAPI | Actix-web | Axum | FastAPI (Python) |
123+
|:--------|:-------:|:---------:|:----:|:----------------:|
124+
| Performance | ~92k req/s | ~105k | ~100k | ~12k |
125+
| Ergonomics | High | Low | Medium | High |
126+
| AI/LLM native format (TOON) | Yes | No | No | No |
127+
| Request replay / time-travel debug | Built-in | No | No | 3rd-party |
128+
| Circuit breaker / retry | Built-in | 3rd-party | 3rd-party | 3rd-party |
129+
| Adaptive execution paths | 3-tier | No | No | N/A |
130+
| OpenAPI from code | Compile-time derive | 3rd-party | 3rd-party | Built-in |
131+
| HTTP/3 (QUIC) | Built-in | No | 3rd-party | No |
132+
| Background jobs | Built-in | 3rd-party | 3rd-party | 3rd-party |
133+
| API stability model | Facade + CI contract | Direct | Direct | Stable |
134+
135+
## Quick Start
78136

79137
```rust
80138
use rustapi_rs::prelude::*;
@@ -89,12 +147,13 @@ async fn hello(Path(name): Path<String>) -> Json<Message> {
89147

90148
#[rustapi_rs::main]
91149
async fn main() {
92-
// 1 line to rule them all: Auto-discovery, OpenAPI, Validation
93150
RustApi::auto().run("127.0.0.1:8080").await
94151
}
95152
```
96153

97-
Prefer a shorter macro prefix? You can rename the crate in `Cargo.toml` and use the same macros:
154+
`RustApi::auto()` collects all macro-annotated handlers, generates OpenAPI documentation (served at `/docs`), and starts a multi-threaded tokio runtime.
155+
156+
You can shorten the macro prefix by renaming the crate:
98157

99158
```toml
100159
[dependencies]
@@ -108,57 +167,45 @@ use api::prelude::*;
108167
async fn list_users() -> &'static str { "ok" }
109168
```
110169

111-
**That's it.** You get:
112-
***Swagger UI** at `/docs`
113-
***Input Validation**
114-
***Multi-threaded Runtime**
115-
***Zero Config**
116-
117-
## Feature Taxonomy (Stable)
170+
## Feature Flags
118171

119-
RustAPI now groups features into three namespaces:
172+
Features are organized into three namespaces:
120173

121174
| Namespace | Purpose | Examples |
122-
|:--|:--|:--|
175+
|:----------|:--------|:--------|
123176
| `core-*` | Core framework capabilities | `core-openapi`, `core-tracing`, `core-http3` |
124-
| `protocol-*` | Optional protocol crates | `protocol-toon`, `protocol-ws`, `protocol-view`, `protocol-grpc` |
125-
| `extras-*` | Optional production middleware/integrations | `extras-jwt`, `extras-cors`, `extras-rate-limit`, `extras-replay` |
126-
127-
Meta features:
128-
- `core` (default)
129-
- `protocol-all`
130-
- `extras-all`
131-
- `full = core + protocol-all + extras-all`
177+
| `protocol-*` | Optional protocol support | `protocol-toon`, `protocol-ws`, `protocol-view`, `protocol-grpc` |
178+
| `extras-*` | Production middleware | `extras-jwt`, `extras-cors`, `extras-rate-limit`, `extras-replay` |
132179

133-
## ✨ Latest Release Highlights (v0.1.335)
180+
Meta features: `core` (default), `protocol-all`, `extras-all`, `full`.
134181

135-
***Dual-Stack Runtime**: Simultaneous HTTP/1.1 (TCP) and HTTP/3 (QUIC/UDP) support
136-
***WebSocket**: Full permessage-deflate negotiation and compression
137-
***OpenAPI**: Improved reference integrity and native validation docs
138-
***Async Validation**: Deep integration with application state for complex rules
139-
***gRPC Foundation**: New optional `rustapi-grpc` crate with Tonic/Prost integration and side-by-side HTTP + gRPC runners (`run_rustapi_and_grpc`, `run_rustapi_and_grpc_with_shutdown`)
140-
***CLI DX Update**: `cargo rustapi new` interactive feature selection now includes `grpc`
182+
## Recent Changes (v0.1.335)
141183

142-
## 🗺️ Public Roadmap: Next 30 Days
184+
- Dual-stack runtime: simultaneous HTTP/1.1 (TCP) and HTTP/3 (QUIC/UDP)
185+
- WebSocket permessage-deflate compression
186+
- Improved OpenAPI reference integrity and validation documentation
187+
- Async validation with application state integration
188+
- `rustapi-grpc` crate: optional Tonic/Prost-based gRPC alongside HTTP (`run_rustapi_and_grpc`)
189+
- `cargo rustapi new` now includes `grpc` in interactive feature selection
143190

144-
We build in public. Here is our immediate focus for **February 2026**:
191+
## Roadmap (February 2026)
145192

146-
* [x] **Visual Status Page**: Automatic health dashboard for all endpoints.
147-
* [x] **gRPC Integration (Foundation)**: First-class optional crate via Tonic (`rustapi-grpc`) with RustAPI facade-level feature flag support.
148-
* [x] **Distributed Tracing**: One-line OpenTelemetry setup.
149-
* [ ] **RustAPI Cloud**: One-click deploy to major cloud providers.
193+
- [x] Visual status page: automatic health dashboard
194+
- [x] gRPC integration via `rustapi-grpc`
195+
- [x] Distributed tracing: OpenTelemetry integration
196+
- [ ] RustAPI Cloud: managed deployment to major cloud providers
150197

151-
## 📚 Documentation
198+
## Documentation
152199

153-
We moved our detailed architecture, recipes, and deep-dives to the **[Cookbook](docs/cookbook/src/SUMMARY.md)**.
200+
Detailed architecture, recipes, and guides are in the [Cookbook](docs/cookbook/src/SUMMARY.md):
154201

155-
* [System Architecture & Diagrams](docs/cookbook/src/architecture/system_overview.md)
156-
* [Performance Benchmarks](docs/cookbook/src/concepts/performance.md)
157-
* [gRPC Integration Guide](docs/cookbook/src/crates/rustapi_grpc.md)
158-
* [Full Examples](crates/rustapi-rs/examples/)
202+
- [System Architecture](docs/cookbook/src/architecture/system_overview.md)
203+
- [Performance Benchmarks](docs/cookbook/src/concepts/performance.md)
204+
- [gRPC Integration Guide](docs/cookbook/src/crates/rustapi_grpc.md)
205+
- [Examples](crates/rustapi-rs/examples/)
159206

160207
---
161208

162209
<div align="center">
163-
<sub>Built with ❤️ by the Tunti3.</sub>
210+
<sub>Built by Tunti35.</sub>
164211
</div>

0 commit comments

Comments
 (0)