<div align="center">
<img src="https://raw.githubusercontent.com/Tuntii/RustAPI/refs/heads/main/assets/logo.jpg" alt="RustAPI Logo" width="200" height="200" />
<h1>RustAPI</h1>
<p>
<strong>The Ergonomic Web Framework for Rust.</strong><br>
Built for Developers, Optimised for Production.
</p>
[](LICENSE)
[](https://www.rust-lang.org/)
[](https://github.com/RustAPI/RustAPI)
</div>
<br />
## π Vision
**RustAPI** brings the developer experience (DX) of modern frameworks like **FastAPI** to the **Rust** ecosystem.
We believe that writing high-performance, type-safe web APIs in Rust shouldn't require fighting with complex trait bounds or massive boilerplate. RustAPI provides a polished, battery-included experience where:
* **API Design is First-Class**: Define your schema, and let the framework handle Validation and OpenAPI documentation automatically.
* **The Engine is Abstracted**: We rely on industry standards like `tokio`, `hyper`, and `matchit` internally, but we expose a stable, user-centric API. This means we can upgrade the engine without breaking your code.
* **Zero Boilerplate**: Extractors and macros do the heavy lifting.
## β¨ Features
- **β‘ Fast & Async**: Built on top of `tokio` and `hyper` 1.0.
- **π‘οΈ Type-Safe**: Request/Response bodies are strictly typed using generic extractors (`Json`, `Query`, `Path`).
- **π Automatic OpenAPI**: Your code *is* your documentation. Swagger UI is served at `/docs` out of the box.
- **β
Built-in Validation**: Add `#[validate(email)]` to your structs and get automatic 422 error handling.
- **π§© Intuitive Routing**: Radix-tree based routing with simple macros `#[rustapi::get]`, `#[rustapi::post]`.
- **π Batteries Included**: Middleware, JWT auth, CORS, rate limiting, and configuration management.
- **π Security First**: JWT authentication, CORS middleware, and IP-based rate limiting out of the box.
- **βοΈ Configuration**: Environment-based config with `.env` file support and typed config extraction.
## π¦ Quick Start
Add `rustapi-rs` to your `Cargo.toml`.
```toml
[dependencies]
rustapi-rs = "0.1"
# Optional features
# rustapi-rs = { version = "0.1", features = ["jwt", "cors", "rate-limit"] }
```
```rust
use rustapi_rs::prelude::*;
/// Define your response schema
#[derive(Serialize, Schema)]
struct HelloResponse {
message: String,
}
/// Define an endpoint
#[rustapi::get("/")]
#[rustapi::tag("General")]
#[rustapi::summary("Hello World Endpoint")]
async fn hello() -> Json<HelloResponse> {
Json(HelloResponse {
message: "Hello from RustAPI!".to_string(),
})
}
/// Run the server
#[rustapi::main]
async fn main() -> Result<()> {
RustApi::new()
.mount_route(hello_route()) // Auto-generated route handler
.docs("/docs") // Enable Swagger UI
.run("127.0.0.1:8080")
.await
}
```
Visit `http://127.0.0.1:8080/docs` to see your interactive API documentation!
## ποΈ Architecture
RustAPI follows a **Facade Architecture** to ensure long-term stability:
* **`rustapi-rs`**: The public-facing crate. It re-exports carefully selected types and traits to provide a clean surface.
* **`rustapi-core`**: The internal engine. Handles the HTTP protocol, routing logic, and glue code.
* **`rustapi-macros`**: Powers the ergonomic attributes like `#[rustapi::main]` and `#[rustapi::get]`.
* **`rustapi-openapi` / `rustapi-validate`**: Specialized crates that wrap external ecosystems (`utoipa`, `validator`) into our consistent API.
## πΊοΈ Roadmap
- [x] **Phase 1: MVP**: Core routing, extractors, and server.
- [x] **Phase 2: Validation & OpenAPI**: Auto-docs, strict validation, and metadata.
- [x] **Phase 3: Batteries Included**: Authentication (JWT), CORS, Rate Limiting, Middleware, and Configuration.
- [ ] **Phase 4: v1.0 Polish**: Advanced ergonomics, CLI tool, and production hardening.
## π Optional Features
| `jwt` | JWT authentication middleware and `AuthUser<T>` extractor |
| `cors` | CORS middleware with builder pattern configuration |
| `rate-limit` | IP-based rate limiting middleware |
| `config` | Configuration management with `.env` file support |
| `cookies` | Cookie parsing extractor |
| `sqlx` | SQLx database error conversion to ApiError |
| `extras` | Meta feature enabling jwt, cors, and rate-limit |
| `full` | All optional features enabled |
## π License
This project is licensed under either of
* Apache License, Version 2.0
* MIT license
at your option.