Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. Foundations: Start with Handlers & Extractors and System Overview.
  2. Core Crates: Read about rustapi-core and rustapi-macros.
  3. Building Blocks: Try the Creating Resources recipe.
  4. Security: Implement JWT Authentication and CSRF Protection.
  5. Advanced: Explore Performance Tuning and HTTP/3.
  6. Background Jobs: Master rustapi-jobs for async processing.

Why Use the Examples Repository?

BenefitDescription
Structured LearningProgress from beginner β†’ intermediate β†’ advanced
Real-world PatternsProduction-ready implementations you can adapt
Feature DiscoveryFind examples by the features you want to learn
AI-FriendlyModule-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.

StepExampleSkills Learned
1hello-worldBasic routing, handlers, server setup
2crud-apiCRUD operations, extractors, error handling
3auth-apiJWT authentication, protected routes
4middleware-chainCustom middleware, logging, CORS
5sqlx-crudDatabase integration, async queries

Related Cookbook Recipes:


πŸ—οΈ Path 2: Microservices Architect

Design and build distributed systems with RustAPI.

StepExampleSkills Learned
1crud-apiService fundamentals
2middleware-chainCross-cutting concerns
3rate-limit-demoAPI protection, throttling
4microservicesService communication patterns
5microservices-advancedService discovery, Consul integration
6Service MockingTesting microservices with MockServer from rustapi-testing
7Background jobs (conceptual)Background processing with rustapi-jobs, Redis/Postgres backends

Note: The Background jobs (conceptual) step refers to using the rustapi-jobs crate rather than a standalone example project. Related Cookbook Recipes:


⚑ Path 3: Real-time Applications

Build interactive, real-time features with WebSockets.

StepExampleSkills Learned
1hello-worldFramework basics
2websocketWebSocket connections, message handling
3middleware-chainConnection middleware
4graphql-apiSubscriptions, real-time queries

Related Cookbook Recipes:


πŸ€– Path 4: AI/LLM Integration

Build AI-friendly APIs with TOON format and MCP support.

StepExampleSkills Learned
1crud-apiAPI fundamentals
2toon-apiTOON format for LLM-friendly responses
3mcp-serverModel Context Protocol implementation
4proof-of-conceptCombining multiple AI features

Related Cookbook Recipes:


🏒 Path 5: Enterprise Platform

Build robust, observable, and secure systems.

StepFeatureDescription
1ObservabilitySet up OpenTelemetry and Structured Logging
2ResilienceImplement Circuit Breakers and Retries
3Advanced SecurityAdd OAuth2 and Security Headers
4OptimizationConfigure Caching and Deduplication
5Background JobsImplement Reliable Job Queues
6DebuggingSet up Time-Travel Debugging
7Reliable TestingMaster Mocking and Integration Testing

Related Cookbook Recipes:


πŸ“¦ Examples by Category

Getting Started

ExampleDescriptionDifficulty
hello-worldMinimal RustAPI server⭐ Beginner
crud-apiComplete CRUD operations⭐ Beginner

Authentication & Security

ExampleDescriptionDifficulty
auth-apiJWT authentication flow⭐⭐ Intermediate
middleware-chainMiddleware composition⭐⭐ Intermediate
rate-limit-demoAPI rate limiting⭐⭐ Intermediate

Database Integration

ExampleDescriptionDifficulty
sqlx-crudSQLx with PostgreSQL/SQLite⭐⭐ Intermediate
event-sourcingEvent sourcing patterns⭐⭐⭐ Advanced

AI & LLM

ExampleDescriptionDifficulty
toon-apiTOON format responses⭐⭐ Intermediate
mcp-serverModel Context Protocol⭐⭐⭐ Advanced

Real-time & GraphQL

ExampleDescriptionDifficulty
websocketWebSocket chat example⭐⭐ Intermediate
graphql-apiGraphQL with async-graphql⭐⭐⭐ Advanced

Production Patterns

ExampleDescriptionDifficulty
microservicesBasic service communication⭐⭐⭐ Advanced
microservices-advancedConsul service discovery⭐⭐⭐ Advanced
serverless-lambdaAWS Lambda deployment⭐⭐⭐ Advanced

πŸ”§ Feature Matrix

Find examples by the RustAPI features they demonstrate:

FeatureExamples
#[get], #[post] macrosAll examples
State<T> extractorcrud-api, auth-api, sqlx-crud
Json<T> extractorcrud-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 Limitingrate-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 Breakermicroservices
Replay (extras-replay feature)microservices (conceptual)
OpenTelemetry (otel)microservices-advanced
OpenAPI/SwaggerAll 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 endpoints
  • src/main.rs - Entry point with server setup
  • src/handlers.rs - Request handlers (where applicable)
  • Cargo.toml - Dependencies and feature flags
  • Tests demonstrating the TestClient

πŸ“– Cross-Reference: Cookbook ↔ Examples

Cookbook RecipeRelated Examples
Creating Resourcescrud-api, sqlx-crud
JWT Authenticationauth-api
CSRF Protectionauth-api, middleware-chain
Database Integrationsqlx-crud, event-sourcing
File Uploadsfile-upload (planned)
Custom Middlewaremiddleware-chain
Real-time Chatwebsocket
Production Tuningmicroservices-advanced
Resilience Patternsmicroservices
Time-Travel Debuggingmicroservices
Deploymentserverless-lambda

πŸ’‘ Contributing Examples

Have a great example to share? We welcome contributions!

  1. Fork the rustapi-rs-examples repository
  2. Create your example following our structure guidelines
  3. Add comprehensive documentation in README.md
  4. 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


πŸ’¬ Need help? Open an issue in the examples repository or join our community discussions!