Learning & Examples
Welcome to the RustAPI learning resources! This section provides structured learning paths and links to comprehensive real-world examples to help you master the framework.
π Structured Curriculum
New to RustAPI? Follow our step-by-step Structured Learning Path to go from beginner to production-ready.
π Learning Resources
Official Examples Repository
We maintain a comprehensive examples repository with 18 real-world projects demonstrating RustAPIβs full capabilities:
π rustapi-rs-examples - Complete examples from hello-world to production microservices
Cookbook Internal Path
If you prefer reading through documentation first, follow this path through the cookbook:
- Foundations: Start with Handlers & Extractors and System Overview.
- Core Crates: Read about rustapi-core and rustapi-macros.
- Building Blocks: Try the Creating Resources recipe.
- Security: Implement JWT Authentication and CSRF Protection.
- Advanced: Explore Performance Tuning and HTTP/3.
- Background Jobs: Master rustapi-jobs for async processing.
Why Use the Examples Repository?
| Benefit | Description |
|---|---|
| Structured Learning | Progress from beginner β intermediate β advanced |
| Real-world Patterns | Production-ready implementations you can adapt |
| Feature Discovery | Find examples by the features you want to learn |
| AI-Friendly | Module-level docs help AI assistants understand your code |
π― Learning Paths
Choose a learning path based on your goals:
π Path 1: REST API Developer
Build production-ready REST APIs with RustAPI.
| Step | Example | Skills Learned |
|---|---|---|
| 1 | hello-world | Basic routing, handlers, server setup |
| 2 | crud-api | CRUD operations, extractors, error handling |
| 3 | auth-api | JWT authentication, protected routes |
| 4 | middleware-chain | Custom middleware, logging, CORS |
| 5 | sqlx-crud | Database integration, async queries |
Related Cookbook Recipes:
ποΈ Path 2: Microservices Architect
Design and build distributed systems with RustAPI.
| Step | Example | Skills Learned |
|---|---|---|
| 1 | crud-api | Service fundamentals |
| 2 | middleware-chain | Cross-cutting concerns |
| 3 | rate-limit-demo | API protection, throttling |
| 4 | microservices | Service communication patterns |
| 5 | microservices-advanced | Service discovery, Consul integration |
| 6 | Service Mocking | Testing microservices with MockServer from rustapi-testing |
| 7 | Background jobs (conceptual) | Background processing with rustapi-jobs, Redis/Postgres backends |
Note: The Background jobs (conceptual) step refers to using the
rustapi-jobscrate rather than a standalone example project. Related Cookbook Recipes:
β‘ Path 3: Real-time Applications
Build interactive, real-time features with WebSockets.
| Step | Example | Skills Learned |
|---|---|---|
| 1 | hello-world | Framework basics |
| 2 | websocket | WebSocket connections, message handling |
| 3 | middleware-chain | Connection middleware |
| 4 | graphql-api | Subscriptions, real-time queries |
Related Cookbook Recipes:
π€ Path 4: AI/LLM Integration
Build AI-friendly APIs with TOON format and MCP support.
| Step | Example | Skills Learned |
|---|---|---|
| 1 | crud-api | API fundamentals |
| 2 | toon-api | TOON format for LLM-friendly responses |
| 3 | mcp-server | Model Context Protocol implementation |
| 4 | proof-of-concept | Combining multiple AI features |
Related Cookbook Recipes:
π’ Path 5: Enterprise Platform
Build robust, observable, and secure systems.
| Step | Feature | Description |
|---|---|---|
| 1 | Observability | Set up OpenTelemetry and Structured Logging |
| 2 | Resilience | Implement Circuit Breakers and Retries |
| 3 | Advanced Security | Add OAuth2 and Security Headers |
| 4 | Optimization | Configure Caching and Deduplication |
| 5 | Background Jobs | Implement Reliable Job Queues |
| 6 | Debugging | Set up Time-Travel Debugging |
| 7 | Reliable Testing | Master Mocking and Integration Testing |
Related Cookbook Recipes:
- rustapi-testing: The Auditor
- rustapi-extras: The Toolbox
- Time-Travel Debugging
- rustapi-jobs: The Workhorse
- Resilience Patterns
π¦ Examples by Category
Getting Started
| Example | Description | Difficulty |
|---|---|---|
hello-world | Minimal RustAPI server | β Beginner |
crud-api | Complete CRUD operations | β Beginner |
Authentication & Security
| Example | Description | Difficulty |
|---|---|---|
auth-api | JWT authentication flow | ββ Intermediate |
middleware-chain | Middleware composition | ββ Intermediate |
rate-limit-demo | API rate limiting | ββ Intermediate |
Database Integration
| Example | Description | Difficulty |
|---|---|---|
sqlx-crud | SQLx with PostgreSQL/SQLite | ββ Intermediate |
event-sourcing | Event sourcing patterns | βββ Advanced |
AI & LLM
| Example | Description | Difficulty |
|---|---|---|
toon-api | TOON format responses | ββ Intermediate |
mcp-server | Model Context Protocol | βββ Advanced |
Real-time & GraphQL
| Example | Description | Difficulty |
|---|---|---|
websocket | WebSocket chat example | ββ Intermediate |
graphql-api | GraphQL with async-graphql | βββ Advanced |
Production Patterns
| Example | Description | Difficulty |
|---|---|---|
microservices | Basic service communication | βββ Advanced |
microservices-advanced | Consul service discovery | βββ Advanced |
serverless-lambda | AWS Lambda deployment | βββ Advanced |
π§ Feature Matrix
Find examples by the RustAPI features they demonstrate:
| Feature | Examples |
|---|---|
#[get], #[post] macros | All examples |
State<T> extractor | crud-api, auth-api, sqlx-crud |
Json<T> extractor | crud-api, auth-api, graphql-api |
ValidatedJson<T> | auth-api, crud-api |
JWT (extras-jwt feature) | auth-api, microservices |
CORS (extras-cors feature) | middleware-chain, auth-api |
| Rate Limiting | rate-limit-demo, auth-api |
WebSockets (protocol-ws feature) | websocket, graphql-api |
TOON (protocol-toon feature) | toon-api, mcp-server |
OAuth2 (oauth2-client) | auth-api (extended) |
| Circuit Breaker | microservices |
Replay (extras-replay feature) | microservices (conceptual) |
OpenTelemetry (otel) | microservices-advanced |
| OpenAPI/Swagger | All examples |
π¦ Getting Started with Examples
Clone the Repository
git clone https://github.com/Tuntii/rustapi-rs-examples.git
cd rustapi-rs-examples
Run an Example
cd hello-world
cargo run
Test an Example
# Most examples have tests
cargo test
# Or use the TestClient
cd ../crud-api
cargo test
Explore the Structure
Each example includes:
README.md- Detailed documentation with API endpointssrc/main.rs- Entry point with server setupsrc/handlers.rs- Request handlers (where applicable)Cargo.toml- Dependencies and feature flags- Tests demonstrating the TestClient
π Cross-Reference: Cookbook β Examples
| Cookbook Recipe | Related Examples |
|---|---|
| Creating Resources | crud-api, sqlx-crud |
| JWT Authentication | auth-api |
| CSRF Protection | auth-api, middleware-chain |
| Database Integration | sqlx-crud, event-sourcing |
| File Uploads | file-upload (planned) |
| Custom Middleware | middleware-chain |
| Real-time Chat | websocket |
| Production Tuning | microservices-advanced |
| Resilience Patterns | microservices |
| Time-Travel Debugging | microservices |
| Deployment | serverless-lambda |
π‘ Contributing Examples
Have a great example to share? We welcome contributions!
- Fork the rustapi-rs-examples repository
- Create your example following our structure guidelines
- Add comprehensive documentation in README.md
- Submit a pull request
Example Guidelines
- Include a clear README with prerequisites and API endpoints
- Add code comments explaining RustAPI-specific patterns
- Include working tests using
rustapi-testing - List the feature flags used
π Additional Resources
- RustAPI GitHub - Framework source code
- API Reference - Generated documentation
- Feature Flags Reference - All available features
- Architecture Guide - How RustAPI works internally
π¬ Need help? Open an issue in the examples repository or join our community discussions!