Torch ๐ฅ
The web framework that doesn't get in your way.
Torch is a fast, secure, and production-ready web framework for Rust. Built on Tokio and Hyper, it provides everything you need to build modern web applications with minimal configuration.
use ;
async
Why developers choose Torch:
- ๐ Blazing Fast - Built on Tokio + Hyper for maximum performance
- ๐ก๏ธ Secure by Design - Security features and beautiful error pages included
- ๐ Production Ready - Monitoring, caching, and database support
- โก Real-time Capable - WebSocket and SSE support out of the box
- ๐ฏ Simple & Familiar - Sinatra-inspired API that just works
- ๐ Fun Error Pages - Beautiful 404 pages with rotating flame-themed messages
โจ Features
๐ High Performance
- Built on Tokio + Hyper for maximum async performance
- Handles thousands of concurrent connections efficiently
- Zero-copy parsing and minimal allocations
- HTTP/1.1 and HTTP/2 support
๐ก๏ธ Security First
- Input validation and sanitization
- HMAC request signing for API security
- IP whitelisting and rate limiting
- Security headers and CSRF protection
๐ Production Ready
- Structured logging with tracing support
- Metrics collection for monitoring
- Health checks and graceful shutdown
- Configuration management via TOML and environment variables
โก Real-time Support
- WebSocket support for real-time applications
- Server-Sent Events (SSE) for live updates
- Connection management and broadcasting
๐๏ธ Database & Caching
- PostgreSQL support with connection pooling
- Redis caching integration
- Query builder for safe database operations
- Migration runner for schema management
๏ฟฝ Beautiful Error Pages
- Stunning default error pages with Torch branding
- Sinatra-inspired 404 messages with flame themes
- Fully customizable error page templates
- Responsive design that works on all devices
๐ง Developer Experience
- Sinatra-inspired API - familiar and intuitive
- Type-safe request/response handling
- Middleware system for composable functionality
- Hot reloading in development mode
๐ Quick Start
Installation
Add Torch to your Cargo.toml
:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
# For JSON support (recommended)
= { = "0.1.0", = ["json"] }
# For production features
= { = "0.1.0", = ["production"] }
# All features
= { = "0.1.0", = ["production", "websocket", "database", "cache"] }
Hello World
use ;
async
Try the Example
# Clone the repository
# Run the hello world example
# Visit http://localhost:3000 to see it in action!
๐จ Beautiful Error Pages
One of Torch's standout features is its beautiful, Sinatra-inspired error pages:
Fun 404 Messages
Torch includes rotating 404 messages with flame themes:
- "๐ฅ Torch doesn't know this ditty, but it's got plenty of other hot tracks!"
- "๐ฅ This path hasn't been lit by the Torch yet."
- "๐ฅ Even the brightest flame can't illuminate this missing page."
Stunning Design
- Modern dark theme with professional gradients
- Torch branding with beautiful SVG flame logo
- Fully responsive - works on desktop, tablet, and mobile
- Smooth animations and hover effects
Customizable
use ErrorPages;
let custom_pages = new
.custom_404
.custom_500;
let app = new
.error_pages;
๐ง Feature Flags
Torch uses feature flags to keep your binary size small:
default
- Includes JSON supportjson
- JSON serialization with serdeproduction
- All production features (monitoring, security, etc.)security
- Security middleware and utilitieswebsocket
- WebSocket and real-time featuresdatabase
- PostgreSQL support with connection poolingcache
- Redis caching integrationapi
- API documentation generationconfig
- TOML configuration supportmonitoring
- Metrics and structured logging
๐๏ธ Architecture
Torch is built on proven Rust technologies:
- Tokio - Async runtime for high performance
- Hyper - Fast HTTP implementation
- Tower - Middleware and service abstractions
- Serde - Serialization framework
- Tracing - Structured logging and diagnostics
๐ง Configuration
Torch supports configuration through TOML files and environment variables.
Configuration File
Create a torch.toml
file in your project root:
[]
= "0.0.0.0"
= 8080
= 10000
= 30
[]
= true
= true
= true
= 100
[]
= true
= true
= "info"
[]
= "postgresql://user:pass@localhost/db"
= 10
[]
= "redis://localhost:6379"
= 3600
Environment Variables
๐ก๏ธ Security Features
use *;
// Input validation and sanitization
let app = new
.middleware
.middleware
.middleware; // 100 requests per second
// HMAC request signing
let signing = new;
let app = app.middleware;
// IP whitelisting
let whitelist = new
.allow_ip
.allow_range;
let app = app.middleware;
๐ Production Features
use *;
// Metrics and monitoring
let app = new
.middleware
.middleware
.middleware;
// Health check endpoint
let app = app.get;
๐ Middleware System
Torch provides a powerful and flexible middleware system:
use *;
// Built-in middleware
let app = new
.middleware
.middleware
.middleware
.middleware;
// Custom middleware
let app = app.middleware;
๐ฏ Use Cases
Web APIs
- REST APIs with JSON serialization
- GraphQL endpoints
- Microservices architecture
- Real-time applications with WebSockets
Production Applications
- High-traffic websites with caching
- Enterprise applications with security
- Data processing pipelines
- Integration services with monitoring
๐ Performance
Torch is built for speed and efficiency:
Why Torch is fast:
- Zero-copy parsing - Minimal allocations in hot paths
- Async all the way down - Built on Tokio's proven runtime
- Smart defaults - Optimized configurations out of the box
- Efficient routing - Fast path matching with minimal overhead
Benchmark it yourself:
# Clone the repository
# Run the hello world example
# Test with your favorite load testing tool
๐งช Try It Now
# Clone and run in 30 seconds
# Run the hello world example
# Visit http://localhost:3000 to see:
# - Hello World endpoint
# - Path parameters (/hello/:name)
# - JSON responses (/json)
# - Beautiful 404 pages (try /nonexistent)
๐ Requirements
- Rust 1.75+ (uses latest async features)
- Tokio runtime (included with Torch)
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone the repository
# Run tests
# Run the example
# Check formatting
# Run clippy
๐ License
This project is licensed under the MIT OR Apache-2.0 license.
๐ Acknowledgments
- Sinatra - Inspired our simple, intuitive API design
- Axum - Architectural inspiration for middleware
- Rust Community - For building an amazing ecosystem
๐ What's Next?
- โญ Star this repo if Torch looks useful to you
- ๐งช Try the example to see how it feels
- ๐ฅ Build something awesome and let us know about it
- ๐ค Contribute - we'd love your help making Torch even better
Join the Community
- ๐ Found a bug? Open an issue
- ๐ก Have an idea? Start a discussion
- ๐ค Want to contribute? Check out CONTRIBUTING.md
- ๐ข Using Torch? We'd love to hear your story!
Built with โค๏ธ and ๐ฅ for developers who ship fast
Torch - The web framework that doesn't get in your way ๐ฅ