Gotcha
An enhanced web framework built on top of Axum, providing additional features and conveniences for building robust web applications in Rust.
✨ Features
- 🚀 Built on Axum - High performance and reliability
- 📚 Automatic OpenAPI - Generate documentation from your code
- 📊 Prometheus Metrics - Built-in metrics collection
- 🌐 CORS Support - Cross-origin resource sharing
- 🔌 WebSocket & SSE - Real-time endpoints, re-exported and ready
- 📁 Static Files - Serve static content effortlessly
- ⏰ Task Scheduling - Cron and interval-based background tasks
- 💌 Message System - Built-in inter-service communication
- ⚙️ Smart Configuration - Environment-based config with variable resolution
- 🏗️ Two APIs - Choose between simple builder API or advanced trait-based API
🚀 Quick Start
Simple Builder API (Recommended for new projects)
use *;
async
Advanced Trait API (For complex applications)
use *;
// The application's own config and state extract directly, thanks to `#[config]` / `#[state]`.
async
async
async
📦 Installation
Add Gotcha to your Cargo.toml:
[]
= "0.4"
= { = "1", = ["macros", "rt-multi-thread"] }
= { = "1", = ["derive"] }
Optional Features
Enable additional features as needed:
[]
= { = "0.4", = ["openapi", "prometheus", "cors", "static_files", "task"] }
Available features:
openapi- Automatic OpenAPI/Swagger documentationprometheus- Metrics collection and expositioncors- Cross-Origin Resource Sharing supportstatic_files- Static file serving capabilitiestask- Background task scheduling with cron support
📖 Documentation & Examples
OpenAPI Documentation
With the openapi feature enabled, use the #[api] macro for automatic documentation:
use *;
/// Get user by ID
async
Visit these endpoints when running:
/redoc- ReDoc documentation interface/scalar- Scalar documentation interface/openapi.json- Raw OpenAPI specification
Configuration System
Create a configurations/application.toml file. Your application's own settings live at the top
level; the framework's are in the reserved [server] section:
= "${DATABASE_URL}"
= "${API_KEY}"
= "My Gotcha App"
[]
= "127.0.0.1"
= 3000
Mark your config type with #[config] to extract it directly in handlers:
use *;
async
The server settings are their own extractor, State<ServerConfig>; State<ConfigWrapper<Config>>
still gives you both at once and derefs to your config.
Configuration supports:
-
Environment variable resolution inside values:
${ENV_VAR} -
Path variable resolution:
${app.database.name} -
Profile-based overrides via
GOTCHA_ACTIVE_PROFILEenvironment variable -
Environment overrides with the
APP_prefix, where__separates nested sections:variable overrides APP_APP_NAME=xthe top-level app_namefieldAPP_SERVER__PORT=8080portinside[server]A single underscore stays part of the field name, so snake_case fields are addressable, and typed fields (numbers, booleans) parse the value rather than rejecting it.
Task Scheduling
Requires the task feature.
use *;
use Duration;
#
🏗️ Architecture
Gotcha is organized as a Rust workspace with the following structure:
gotcha/
├── gotcha/ # Main framework crate
├── gotcha_macro/ # Procedural macros
└── examples/ # Example applications
├── basic/ # Basic usage example
├── openapi/ # OpenAPI documentation example
├── configuration/# Configuration management example
├── task/ # Background tasks example
├── message/ # Message system example
└── simple/ # Builder API example
Core Concepts
- GotchaApp trait - Main application interface for complex apps
- Gotcha builder - Simple API for straightforward applications
- GotchaRouter - Enhanced Axum router with OpenAPI integration
- GotchaContext - Application context combining state and configuration
- ConfigWrapper - Configuration management with environment resolution
🔧 Development
Building
# Build main crate
# Build with all features
# Test all feature combinations
Testing
# Run tests
# Test with specific features
Code Quality
# Format code
# Run linter
# Generate documentation
📚 Examples
Run any example to see Gotcha in action:
&& && && &&
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
python3 test-feature-matrix.py - Submit a pull request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.