Foxtive-Ntex
A high-performance micro-framework built on Foxtive and ntex, designed for building production-ready Rust web services with minimal boilerplate.
Features
- High Performance: Built on ntex, one of the fastest Rust web frameworks
- Type Safety: Leverage Rust's type system for safe request handling
- Minimal Boilerplate: Focus on business logic, not framework configuration
- Extensible State Management: Custom state injection with type-safe access
- Graceful Shutdown: Coordinated service cleanup with priority-based shutdown
- Body Parsing: Automatic JSON deserialization with configurable size limits
- CORS Support: Built-in CORS middleware with flexible configuration
- JWT Authentication: Optional JWT token extraction and validation
- File Uploads: Multipart form data support (optional feature)
- Database Integration: Optional database connection pooling
- Validation: Request validation with validator crate (optional feature)
Quick Start
Add to your Cargo.toml:
[]
= "0.30"
Simple Server
use *;
use Environment;
use ;
use ;
use StructResponseExt;
use ;
use ;
async
async
Run with:
Test it:
Examples
The repository includes several examples demonstrating different use cases:
Simple Server
Basic HTTP server with JSON responses.
REST API Server
Production-ready REST API with custom state and graceful shutdown.
Custom State
Demonstrates custom state injection and type-safe access.
Core Concepts
Server Configuration
Foxtive-Ntex provides three preset configurations:
dev_mode(): Single worker, relaxed timeouts for developmentproduction_mode(): Optimized settings matching CPU coreshigh_performance_mode(): Maximum throughput for high-traffic APIs
dev_mode
.workers
.max_conn
.keep_alive
.route_factory
.start
.await?;
Custom State Management
Inject custom services into your application state:
use app_state_ext;
use fox_state;
// Generate type-safe accessors
app_state_ext!
// In handlers
async
Request Body Parsing
Automatic JSON deserialization with size limits:
use JsonBody;
use Deserialize;
async
Configure body size limits:
use BodyConfig;
let config = default
.json_limit // 1 MB
.string_limit // 512 KB
.byte_limit; // 2 MB
Graceful Shutdown
Register services for coordinated cleanup:
dev_mode
.shutdown_config
.register_shutdown_service
.register_shutdown_service
.start
.await?;
Services shut down in priority order (lower number = first).
Bootstrap Callback
Run initialization logic before the server starts:
dev_mode
.start
.await?;
Optional Features
Enable features in your Cargo.toml:
[]
= { = "0.30", = ["jwt", "multipart", "validator"] }
Available features:
jwt: JWT authentication supportmultipart: File upload handlingvalidator: Request validationstatic: Static file servingdatabase: Database connection poolingstrum: Enum utilities
Architecture
Foxtive-Ntex is built on a layered architecture:
- ntex: High-performance HTTP server foundation
- Foxtive: Core utilities, environment management, error handling
- Foxtive-Ntex: Web framework layer with routing, middleware, state management
This design provides the performance of ntex with the developer experience of a full-featured framework.
Testing
Run the test suite:
All tests pass with 123 unit tests covering core functionality.
Migration Guide
From 0.29 to 0.30
JsonConfigrenamed toBodyConfig(old name deprecated)- Added separate limits for JSON, string, and byte bodies
boot_thread()renamed toroute_factory()(old name deprecated)JsonBody<T>now discards raw JSON after deserialization (memory optimization)
From 0.28 to 0.29
DeJsonBodyremoved; useJsonBody<T>with automatic deserializationJsonBodynow implementsDereffor direct field access- Added
route_factory_arc()for shared route factories
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE for details.
Changelog
See CHANGELOG.md for version history.