elif-http-derive
Derive macros for the elif-http declarative routing and controller system.
Overview
This crate provides procedural macros that enable declarative controller development in elif.rs, significantly reducing boilerplate and improving developer experience.
Features
#[controller]
: Define controller base path and metadata#[get]
,#[post]
,#[put]
,#[delete]
, etc.: HTTP method routing macros#[middleware]
: Apply middleware to controllers and methods#[param]
: Route parameter specifications#[body]
: Request body type specifications
Usage
Add this to your Cargo.toml
:
[]
= { = "0.7.0", = ["derive"] }
Example
use ;
;
Comparison with Manual Registration
Before (Manual Registration)
After (Declarative Macros)
;
Result: ~70% reduction in boilerplate code
Status
This is the initial implementation for issue #241 in the elif.rs epic #236. The current implementation provides:
- ✅ Basic macro structure and compilation
- ✅ Integration with elif-http crate
- ✅ Compile-time validation of macro usage
- ✅ Comprehensive test suite with trybuild
- ✅ Meaningful error messages for invalid usage
- ✅ All HTTP method macros (GET, POST, PUT, DELETE, etc.)
- 🚧 Runtime route registration (needs integration with controller system)
- 🚧 Automatic ElifController trait implementation
- 🚧 Advanced parameter validation and extraction
Testing
The crate includes comprehensive testing:
- Unit tests: Basic functionality and parsing
- Integration tests: Real macro usage verification
- UI tests with trybuild: Compile-time behavior validation
- Pass tests for valid usage scenarios
- Fail tests with expected error messages
- Edge case handling verification
Development Status
This implementation represents the foundation for declarative routing macros. Future enhancements will include:
- Route Registration: Automatic integration with the routing system
- Parameter Extraction: Advanced parameter parsing and validation
- Middleware Composition: Intelligent middleware ordering and application
- Compile-time Validation: Route conflict detection and optimization
- IDE Support: Enhanced autocomplete and error reporting
License
MIT