Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
5,298 changes: 5,298 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[workspace]
members = [
"hello-world",
"crud-api",
"auth-api",
"cors-test",
"sqlx-crud",
"event-sourcing",
"graphql-api",
"mcp-server",
"microservices",
"microservices-advanced",
"middleware-chain",
"phase11-demo",
"rate-limit-demo",
"templates",
"toon-api",
"websocket",
"proof-of-concept",
]

[workspace.dependencies]
rustapi-rs = "0.1"
rustapi-core = "0.1"
rustapi-macros = "0.1"
rustapi-extras = "0.1"
tokio = { version = "1", features = ["full", "sync"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
validator = "0.16"
utoipa = "4"
async-trait = "0.1"
thiserror = "1"
uuid = { version = "1.6", features = ["v4", "serde"] }
futures-util = "0.3"
36 changes: 18 additions & 18 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RustAPI uses Cargo feature flags to enable optional functionality. This modular

```toml
[dependencies]
rustapi-rs = { version = "0.2", features = ["jwt", "cors"] }
rustapi-rs = { version = "0.1", features = ["jwt", "cors"] }
```

---
Expand All @@ -24,7 +24,7 @@ rustapi-rs = { version = "0.2", features = ["jwt", "cors"] }
**Enables all features** — Use this when you need everything or for rapid prototyping.

```toml
rustapi-rs = { version = "0.2", features = ["full"] }
rustapi-rs = { version = "0.1", features = ["full"] }
```

**Includes**: jwt, cors, rate-limit, toon, ws, view, swagger-ui, and all middleware
Expand All @@ -45,7 +45,7 @@ rustapi-rs = { version = "0.2", features = ["full"] }
**JWT Authentication** — Adds `JwtLayer` middleware and `AuthUser<T>` extractor.

```toml
rustapi-rs = { version = "0.2", features = ["jwt"] }
rustapi-rs = { version = "0.1", features = ["jwt"] }
```

**Provides**:
Expand Down Expand Up @@ -98,7 +98,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
**Cross-Origin Resource Sharing** — Adds `CorsLayer` for configuring CORS headers.

```toml
rustapi-rs = { version = "0.2", features = ["cors"] }
rustapi-rs = { version = "0.1", features = ["cors"] }
```

**Provides**:
Expand Down Expand Up @@ -141,7 +141,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
**Rate Limiting** — Adds `RateLimitLayer` for IP-based request throttling.

```toml
rustapi-rs = { version = "0.2", features = ["rate-limit"] }
rustapi-rs = { version = "0.1", features = ["rate-limit"] }
```

**Provides**:
Expand Down Expand Up @@ -185,7 +185,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
**Token-Oriented Object Notation** — AI-optimized response format with 50-58% token savings.

```toml
rustapi-rs = { version = "0.2", features = ["toon"] }
rustapi-rs = { version = "0.1", features = ["toon"] }
```

**Provides**:
Expand Down Expand Up @@ -239,7 +239,7 @@ curl -H "Accept: application/toon" http://localhost:8080/user/1
**WebSocket Support** — Real-time bidirectional communication.

```toml
rustapi-rs = { version = "0.2", features = ["ws"] }
rustapi-rs = { version = "0.1", features = ["ws"] }
```

**Provides**:
Expand Down Expand Up @@ -278,7 +278,7 @@ async fn websocket_handler(ws: WebSocket) -> WsConnection {
**Template Rendering** — Server-side HTML with Tera templates.

```toml
rustapi-rs = { version = "0.2", features = ["view"] }
rustapi-rs = { version = "0.1", features = ["view"] }
```

**Provides**:
Expand Down Expand Up @@ -319,7 +319,7 @@ async fn index(engine: State<ViewEngine>) -> View<PageContext> {
**Swagger UI** — Interactive API documentation at `/docs`.

```toml
rustapi-rs = { version = "0.2", features = ["swagger-ui"] }
rustapi-rs = { version = "0.1", features = ["swagger-ui"] }
```

**Provides**:
Expand All @@ -344,7 +344,7 @@ Some examples use additional RustAPI ecosystem crates:
Low-level core functionality for advanced use cases.

```toml
rustapi-core = { version = "0.2" }
rustapi-core = { version = "0.1" }
```

**Used in**: middleware-chain, phase11-demo
Expand All @@ -354,7 +354,7 @@ rustapi-core = { version = "0.2" }
Procedural macros (usually re-exported from `rustapi-rs`).

```toml
rustapi-macros = { version = "0.2" }
rustapi-macros = { version = "0.1" }
```

**Used in**: cors-test, phase11-demo
Expand All @@ -364,7 +364,7 @@ rustapi-macros = { version = "0.2" }
Additional middleware and utilities.

```toml
rustapi-extras = { version = "0.2", features = ["sqlx", "timeout", "guard"] }
rustapi-extras = { version = "0.1", features = ["sqlx", "timeout", "guard"] }
```

**Features**:
Expand All @@ -385,28 +385,28 @@ Common feature combinations for different use cases:

### REST API with Auth
```toml
rustapi-rs = { version = "0.2", features = ["jwt", "cors", "rate-limit"] }
rustapi-rs = { version = "0.1", features = ["jwt", "cors", "rate-limit"] }
```

### AI/LLM Backend
```toml
rustapi-rs = { version = "0.2", features = ["toon", "cors"] }
rustapi-rs = { version = "0.1", features = ["toon", "cors"] }
```

### Full-Stack Web App
```toml
rustapi-rs = { version = "0.2", features = ["view", "jwt", "cors"] }
rustapi-rs = { version = "0.1", features = ["view", "jwt", "cors"] }
```

### Real-time Application
```toml
rustapi-rs = { version = "0.2", features = ["ws", "cors"] }
rustapi-rs = { version = "0.1", features = ["ws", "cors"] }
```

### Production API
```toml
rustapi-rs = { version = "0.2", features = ["jwt", "cors", "rate-limit", "swagger-ui"] }
rustapi-extras = { version = "0.2", features = ["timeout", "logging", "circuit-breaker"] }
rustapi-rs = { version = "0.1", features = ["jwt", "cors", "rate-limit", "swagger-ui"] }
rustapi-extras = { version = "0.1", features = ["timeout", "logging", "circuit-breaker"] }
```

---
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Each example maps to sections in the [RustAPI Cookbook](https://tuntii.github.io
edition = "2021"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs", features = ["full"] }
rustapi-rs = { version = "0.1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
```
Expand Down
6 changes: 3 additions & 3 deletions auth-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ publish = false
description = "Authentication example demonstrating JWT middleware"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs", features = ["jwt", "rate-limit"] }
tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
rustapi-rs = { workspace = true, features = ["jwt", "rate-limit"] }
tokio = { workspace = true }
serde = { workspace = true }
validator = { workspace = true }
utoipa = { workspace = true }
2 changes: 1 addition & 1 deletion auth-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async fn handler(AuthUser(claims): AuthUser<Claims>) -> impl IntoResponse {

```toml
[dependencies]
rustapi-rs = { version = "0.2", features = ["jwt", "rate-limit"] }
rustapi-rs = { version = "0.1", features = ["jwt", "rate-limit"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
validator = "0.16"
Expand Down
10 changes: 5 additions & 5 deletions cors-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs", features = ["cors", "rate-limit"] }
rustapi-macros = { path = "../../crates/rustapi-macros" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
rustapi-rs = { workspace = true, features = ["cors", "rate-limit"] }
rustapi-macros = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
2 changes: 1 addition & 1 deletion cors-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ RustApi::new()

```toml
[dependencies]
rustapi-rs = { version = "0.2", features = ["cors", "rate-limit"] }
rustapi-rs = { version = "0.1", features = ["cors", "rate-limit"] }
tokio = { version = "1", features = ["full"] }
serde = "1"
```
Expand Down
6 changes: 3 additions & 3 deletions crud-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ publish = false
description = "CRUD API example demonstrating all RustAPI features"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs", features = ["full"] }
tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
rustapi-rs = { workspace = true, features = ["full"] }
tokio = { workspace = true }
serde = { workspace = true }
validator = { workspace = true }
utoipa = { workspace = true }
2 changes: 1 addition & 1 deletion crud-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub struct PaginatedResponse<T> {

```toml
[dependencies]
rustapi-rs = { version = "0.2", features = ["full"] }
rustapi-rs = { version = "0.1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
validator = "0.16"
Expand Down
6 changes: 3 additions & 3 deletions event-sourcing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
rustapi-rs = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
uuid = { workspace = true, features = ["v4", "serde"] }
thiserror = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion event-sourcing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ let account = events.iter().fold(BankAccount::default(), |mut acc, e| {

```toml
[dependencies]
rustapi-rs = { version = "0.2" }
rustapi-rs = { version = "0.1" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
dashmap = "5.5"
Expand Down
10 changes: 5 additions & 5 deletions graphql-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
rustapi-rs = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
async-graphql = "7.0"
async-graphql-axum = "7.0"
utoipa = "4.2"
utoipa = { workspace = true }
6 changes: 3 additions & 3 deletions hello-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"
publish = false

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs" }
tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
rustapi-rs = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
validator = { workspace = true }
utoipa = { workspace = true }
8 changes: 4 additions & 4 deletions mcp-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs", features = ["toon"] }
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.41", features = ["full"] }
utoipa = "4.2"
rustapi-rs = { workspace = true, features = ["toon"] }
serde = { workspace = true }
tokio = { workspace = true }
utoipa = { workspace = true }
6 changes: 3 additions & 3 deletions microservices-advanced/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustapi-rs = { path = "../../crates/rustapi-rs" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
rustapi-rs = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
reqwest = { version = "0.12", features = ["json"] }
tracing = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion microservices-advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn select_instance(instances: &[ServiceInstance]) -> Option<&ServiceInstance> {

```toml
[dependencies]
rustapi-rs = { version = "0.2" }
rustapi-rs = { version = "0.1" }
tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.12", features = ["json"] }
dashmap = "5.5"
Expand Down
13 changes: 10 additions & 3 deletions microservices-advanced/src/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ struct Product {
price: f64,
}

async fn get_products() -> Json<Vec<Product>> {
Json(vec![
#[derive(Serialize, Schema)]
struct ProductList {
products: Vec<Product>,
}

async fn get_products() -> Json<ProductList> {
Json(ProductList {
products: vec![
Product {
id: "1".to_string(),
name: "Laptop".to_string(),
Expand All @@ -43,7 +49,8 @@ async fn get_products() -> Json<Vec<Product>> {
name: "Mouse".to_string(),
price: 29.99,
},
])
],
})
}

async fn get_product(Path(id): Path<String>) -> Result<Json<Product>, ApiError> {
Expand Down
Loading