The power of Rust. Modern DX. LLM-ready.
RustAPI - A Rust API framework designed for AI-first development | Product Hunt
RustAPI redefines API development for the AI era.
We combine Rust's performance and safety with FastAPI's ergonomics. Write type-safe, production-ready APIs without fighting trait bounds. MCP servers, LLM integrations, or classic REST APIs β one framework for all.
"API surface is ours, engines can change."
RustAPI follows a Facade Architecture β a stable, ergonomic public API that shields you from internal complexity and breaking changes.
| Principle | What It Means |
|---|---|
| π― 5-Line APIs | A working REST endpoint in 5 lines. No ceremony. |
| π‘οΈ Stable Surface | Your code depends on rustapi-rs. Internal crates (hyper, tokio, validator) are implementation details. |
| π Engines Change | We can swap hyper for h3, upgrade tokio, or replace validator β your code stays the same. |
| π Batteries Included | JWT, CORS, Rate Limiting, OpenAPI β all built-in, all optional via feature flags. |
| π€ LLM-First | TOON format, token counting headers, MCP-ready. Built for the AI era. |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application β
β use rustapi_rs::prelude::* β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β rustapi-rs (Facade) β
β Stable API ββ Never Breaks β
βββββββββββββββββ¬ββββββββββββββββ¬ββββββββββββββββ¬ββββββββββββββ€
β rustapi-core β rustapi-toon β rustapi-extrasβ ... β
β (hyper) β (serde) β (jwt) β β
βββββββββββββββββ΄ββββββββββββββββ΄ββββββββββββββββ΄ββββββββββββββ€
β Foundation: tokio, serde, hyper β
β β Can be upgraded/swapped internally β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Internal upgrades don't break your code. When hyper 2.0 releases, we update rustapi-core. Your RustApi::new() keeps working.
π Read more: docs/PHILOSOPHY.md | docs/ARCHITECTURE.md
use rustapi_rs::prelude::*; #[rustapi_rs::get("/hello/{name}")] async fn hello(Path(name): Path<String>) -> Json<Message> { Json(Message { greeting: format!("Hello, {name}!") }) } #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { RustApi::auto().run("0.0.0.0:8080").await }
5 lines of code. Auto-generated OpenAPI docs. Production-ready.
[dependencies] rustapi-rs = "0.1.4"
use rustapi_rs::prelude::*; #[derive(Serialize, Schema)] struct User { id: u64, name: String } #[rustapi_rs::get("/users/{id}")] async fn get_user(Path(id): Path<u64>) -> Json<User> { Json(User { id, name: "Tunahan".into() }) } #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { // Zero config: all `#[rustapi_rs::get/post/..]` routes are auto-registered. // Swagger UI is enabled at /docs by default (when built with the `swagger-ui` feature). RustApi::auto().run("127.0.0.1:8080").await }
http://localhost:8080/docs β Swagger UI ready.
| Feature | Description |
|---|---|
| Type-Safe Extractors | Json<T>, Query<T>, Path<T> β compile-time guarantees |
| Zero-Config Routing | Macro-decorated routes auto-register at startup (RustApi::auto()) |
| Auto OpenAPI | Your code = your docs. /docs endpoint out of the box |
| Validation | #[validate(email)] β automatic 422 responses |
| JWT Auth | One-line auth with AuthUser<T> extractor |
| CORS & Rate Limit | Production-ready middleware |
| TOON Format | 50-58% token savings for LLMs |
rustapi-rs = { version = "0.1.4", features = ["jwt", "cors", "toon"] }
jwtβ JWT authenticationcorsβ CORS middlewarerate-limitβ IP-based rate limitingtoonβ LLM-optimized responsesfullβ Everything included
All examples in this repository are written in the Phase 6 "zero-config" style.
cargo run -p hello-world cargo run -p crud-api cargo run -p auth-api cargo run -p sqlx-crud cargo run -p toon-api cargo run -p proof-of-concept
RustAPI is built for AI-powered APIs.
TOON (Token-Oriented Object Notation) uses 50-58% fewer tokens than JSON. Ideal for MCP servers, AI agents, and LLM integrations.
use rustapi_rs::toon::{Toon, LlmResponse, AcceptHeader}; // Direct TOON response #[rustapi::get("/ai/users")] async fn ai_users() -> Toon<UsersResponse> { Toon(get_users()) } // Content negotiation: JSON or TOON based on Accept header #[rustapi::get("/users")] async fn users(accept: AcceptHeader) -> LlmResponse<UsersResponse> { LlmResponse::new(get_users(), accept.preferred) } // Headers: X-Token-Count-JSON, X-Token-Count-TOON, X-Token-Savings
Why TOON?
- Compatible with Claude, GPT-4, Gemini β all major LLMs
- Cut your token costs in half
- Optimized for MCP (Model Context Protocol) servers
RustAPI follows a Facade Architecture β a stable public API that shields you from internal changes.
graph TB
subgraph Client["π Client Layer"]
HTTP[HTTP Request]
LLM[LLM/AI Agent]
MCP[MCP Client]
end
subgraph Public["π¦ rustapi-rs (Public Facade)"]
direction TB
Prelude[prelude::*]
Macros["#[rustapi::get/post]<br>#[rustapi::main]"]
Types[Json, Query, Path, Form]
end
subgraph Core["βοΈ rustapi-core (Engine)"]
direction TB
Router[Radix Router<br>matchit]
Extract[Extractors<br>FromRequest trait]
MW[Middleware Stack<br>Tower-like layers]
Resp[Response Builder<br>IntoResponse trait]
end
subgraph Extensions["π Extension Crates"]
direction LR
OpenAPI["rustapi-openapi<br>Swagger/Docs"]
Validate["rustapi-validate<br>Request Validation"]
Toon["rustapi-toon<br>LLM Optimization"]
Extras["rustapi-extras<br>JWT/CORS/RateLimit"]
end
subgraph Foundation["ποΈ Foundation Layer"]
direction LR
Tokio[tokio<br>Async Runtime]
Hyper[hyper 1.0<br>HTTP Protocol]
Serde[serde<br>Serialization]
end
HTTP --> Public
LLM --> Public
MCP --> Public
Public --> Core
Core --> Extensions
Extensions --> Foundation
Core --> Foundation
sequenceDiagram
participant C as Client
participant R as Router
participant M as Middleware
participant E as Extractors
participant H as Handler
participant S as Serializer
C->>R: HTTP Request
R->>R: Match route (radix tree)
R->>M: Pass to middleware stack
loop Each Middleware
M->>M: Process (JWT, CORS, RateLimit)
end
M->>E: Extract parameters
E->>E: Json<T>, Path<T>, Query<T>
E->>E: Validate with #[validate]
alt Validation Failed
E-->>C: 422 Unprocessable Entity
else Validation OK
E->>H: Call async handler
H->>S: Return response type
alt TOON Enabled
S->>S: Check Accept header
S->>S: Serialize as TOON/JSON
S->>S: Add token count headers
else Standard
S->>S: Serialize as JSON
end
S-->>C: HTTP Response
end
graph BT
subgraph User["Your Application"]
App[main.rs]
end
subgraph Facade["Single Import"]
RS[rustapi-rs]
end
subgraph Internal["Internal Crates"]
Core[rustapi-core]
Macros[rustapi-macros]
OpenAPI[rustapi-openapi]
Validate[rustapi-validate]
Toon[rustapi-toon]
Extras[rustapi-extras]
end
subgraph External["External Dependencies"]
Tokio[tokio]
Hyper[hyper]
Serde[serde]
Utoipa[utoipa]
Validator[validator]
end
App --> RS
RS --> Core
RS --> Macros
RS --> OpenAPI
RS --> Validate
RS -.->|optional| Toon
RS -.->|optional| Extras
Core --> Tokio
Core --> Hyper
Core --> Serde
OpenAPI --> Utoipa
Validate --> Validator
Toon --> Serde
style RS fill:#e1f5fe
style App fill:#c8e6c9
| Principle | Implementation |
|---|---|
| Single Entry Point | use rustapi_rs::prelude::* imports everything you need |
| Zero Boilerplate | Macros generate routing, OpenAPI specs, and validation |
| Compile-Time Safety | Generic extractors catch type errors at compile time |
| Opt-in Complexity | Features like JWT, TOON are behind feature flags |
| Engine Abstraction | Internal hyper/tokio upgrades don't break your code |
| Crate | Role |
|---|---|
rustapi-rs |
Public facade β single use for everything |
rustapi-core |
HTTP engine, routing, extractors, response handling |
rustapi-macros |
Procedural macros: #[rustapi::get], #[rustapi::main] |
rustapi-openapi |
Swagger UI generation, OpenAPI 3.0 spec |
rustapi-validate |
Request body/query validation via #[validate] |
rustapi-toon |
TOON format serializer, content negotiation, LLM headers |
rustapi-extras |
JWT auth, CORS, rate limiting middleware |
- Core framework (routing, extractors, server)
- OpenAPI & Validation
- JWT, CORS, Rate Limiting
- TOON format & LLM optimization
- Coming soon...
MIT or Apache-2.0, at your option.