Production-ready examples demonstrating the full power of RustAPI β the Rust web framework with FastAPI-like developer experience.
π Official Resources:
- π RustAPI Framework β Main repository
- π Cookbook Documentation β Comprehensive guides & recipes
- π¬ Discussions β Community support
"Rust Speed. Python Simplicity. AI Efficiency."
| Metric | RustAPI | Actix | Axum | FastAPI (Python) |
|---|---|---|---|---|
| Performance | ~92k req/s | ~105k | ~100k | ~12k |
| Developer Experience | π’ High | π΄ Low | π‘ Medium | π’ High |
| Boilerplate | Zero | High | Medium | Zero |
| AI/LLM Native | β | β | β | β |
| Type Safety | β | β | β | β |
- π― Zero Boilerplate β
RustApi::auto()discovers all routes automatically - π Auto Documentation β OpenAPI/Swagger at
/docsout of the box - β
Built-in Validation β
#[validate]with detailed error messages - π JWT Authentication β First-class
JwtLayerandAuthUser<T>extractor - π€ AI-First Architecture β TOON format (50-58% token savings), MCP support
- β‘ Middleware Stack β Rate limiting, CORS, logging, circuit breaker, and more
- π Real-time β WebSocket support with broadcast channels
Before running these examples, ensure you have:
# Rust 1.70 or later
rustc --version
# Clone the examples repository
git clone https://github.com/Tuntii/rustapi-rs-examples.git
cd rustapi-rs-examples
# Build all examples
cargo build --releaseOptional dependencies (for specific examples):
- Docker β For
sqlx-crud(PostgreSQL/SQLite) - SQLite β For
sqlx-crudlocal testing
This repository contains 18 production-ready examples organized by category:
| Example | Difficulty | Description | Key Features |
|---|---|---|---|
| hello-world | β | Minimal 20-line API | RustApi::auto(), path params, Json response |
| crud-api | ββ | Complete CRUD operations | Validation, pagination, error handling, body limits |
| proof-of-concept | βββ | Full-featured bookmark manager | JWT, CRUD, SSE, modular handlers, Swagger UI |
| Example | Difficulty | Description | Key Features |
|---|---|---|---|
| auth-api | βββ | JWT authentication system | Login/register, JwtLayer, AuthUser<T>, protected routes |
| rate-limit-demo | ββ | IP-based rate limiting | Per-endpoint limits, burst support, 429 handling |
| middleware-chain | βββ | Custom middleware composition | Request ID, timing, auth, middleware ordering |
| cors-test | ββ | CORS configuration | CorsLayer, allowed origins/methods/headers |
| Example | Difficulty | Description | Key Features |
|---|---|---|---|
| sqlx-crud | βββ | SQLx + SQLite/PostgreSQL | Connection pooling, transactions, migrations |
| event-sourcing | ββββ | Event sourcing pattern | CQRS, domain events, aggregate reconstruction |
| Example | Difficulty | Description | Key Features |
|---|---|---|---|
| toon-api | ββ | Token-optimized responses | ToonResponse, content negotiation, token headers |
| mcp-server | βββ | Model Context Protocol | Tool definitions, resource management, AI agents |
| Example | Difficulty | Description | Key Features |
|---|---|---|---|
| websocket | βββ | WebSocket chat server | Broadcast channels, pub/sub, connection management |
| templates | ββ | Server-side rendering | Tera templates, inheritance, static files |
| Example | Difficulty | Description | Key Features |
|---|---|---|---|
| graphql-api | ββββ | GraphQL integration | async-graphql, queries/mutations, playground |
| microservices | ββββ | API Gateway pattern | Service-to-service communication, routing |
| microservices-advanced | ββββ | Service discovery | Registry, heartbeat, Docker Compose |
| phase11-demo | ββββ | Advanced middleware | Guards, circuit breaker, timeout, logging |
| serverless-lambda | βββ | AWS Lambda deployment | SAM template, cold start optimization |
β οΈ Note:serverless-lambdauses AWS Lambda HTTP runtime instead of RustAPI for serverless deployment patterns.
| Feature | Examples Using It |
|---|---|
RustApi::auto() |
All examples |
Json<T> / JsonResponse |
crud-api, auth-api, proof-of-concept, graphql-api |
#[validate] |
crud-api, auth-api, proof-of-concept |
JwtLayer / AuthUser<T> |
auth-api, middleware-chain, phase11-demo, proof-of-concept |
RateLimitLayer |
rate-limit-demo, auth-api, cors-test, proof-of-concept |
CorsLayer |
cors-test, middleware-chain, proof-of-concept |
ToonResponse |
toon-api, mcp-server |
WebSocket / WsConnection |
websocket |
View<T> / ViewEngine |
templates |
State<T> |
All examples with shared state |
RequestIdLayer |
middleware-chain, phase11-demo |
CircuitBreakerLayer |
phase11-demo |
TimeoutLayer |
phase11-demo |
Each example uses specific Cargo feature flags. See FEATURES.md for detailed documentation.
| Feature Flag | Purpose | Examples |
|---|---|---|
full |
All features enabled | crud-api, phase11-demo |
jwt |
JWT authentication | auth-api, middleware-chain, proof-of-concept |
cors |
CORS middleware | cors-test, middleware-chain, proof-of-concept |
rate-limit |
Rate limiting | rate-limit-demo, auth-api, cors-test, proof-of-concept |
toon |
TOON format for LLMs | toon-api, mcp-server |
ws |
WebSocket support | websocket |
view |
Template rendering | templates |
swagger-ui |
Swagger UI at /docs | toon-api |
# Navigate to repository
cd rustapi-rs-examples
# Run any example
cargo run -p hello-world
# Run with debug logging
RUST_LOG=debug cargo run -p crud-api
# Access Swagger documentation (when running)
# http://127.0.0.1:8080/docs# Hello World
curl http://127.0.0.1:8080/
curl http://127.0.0.1:8080/hello/RustAPI
# CRUD API
curl http://127.0.0.1:8080/users
curl -X POST http://127.0.0.1:8080/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
# Auth API
curl -X POST http://127.0.0.1:8080/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "password"}'For a structured learning experience, follow our recommended progression in LEARNING_PATH.md:
1. hello-world β Basic routing, responses
2. crud-api β Validation, error handling, state management
3. auth-api β JWT authentication, protected routes
4. middleware-chain β Custom middleware, composition
5. proof-of-concept β Full application architecture
Each example maps to sections in the RustAPI Cookbook:
| Example | Cookbook Section |
|---|---|
| hello-world | Getting Started β Quickstart |
| crud-api | Recipes β CRUD Resources |
| auth-api | Recipes β JWT Authentication |
| middleware-chain | Recipes β Custom Middleware |
| sqlx-crud | Recipes β Database Integration |
| websocket | Recipes β WebSockets |
| templates | Crates β rustapi-view |
| toon-api | Crates β rustapi-toon |
-
Create directory:
my-example/ -
Add Cargo.toml:
[package] name = "my-example" version = "0.1.0" edition = "2021" [dependencies] rustapi-rs = { path = "../../crates/rustapi-rs", features = ["full"] } tokio = { version = "1", features = ["full"] } serde = { version = "1", features = ["derive"] }
-
Create src/main.rs:
use rustapi_rs::prelude::*; #[rustapi_rs::get("/")] async fn index() -> &'static str { "Hello from my example!" } #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { RustApi::auto().run("127.0.0.1:8080").await }
-
Run it:
cargo run -p my-example
- redis-cache β Redis caching layer
- sse-events β Server-Sent Events streaming
- grpc-integration β gRPC + REST hybrid API
- distributed-tracing β OpenTelemetry integration
- kubernetes-ready β Health checks, metrics, graceful shutdown
Contributions are welcome! See our Contributing Guide for details.
- Fork this repository
- Create your example in a new directory
- Add comprehensive documentation (README.md)
- Submit a pull request
This project is licensed under the MIT OR Apache-2.0 license, same as RustAPI.
Built with β€οΈ using RustAPI
Framework Β· Cookbook Β· Examples Β· Discussions