Lambda LightWeight HTTP Router
A lightweight, type-safe HTTP router for AWS Lambda functions with support for API Gateway, Application Load Balancer, and WebSocket APIs.
Features
- 🚀 Zero runtime overhead with compile-time route registration
- 🔒 Type-safe route handlers and application state
- 🎯 Path parameter extraction
- 🔄 Support for multiple AWS event types:
- API Gateway HTTP API (v2)
- API Gateway REST API (v1)
- Application Load Balancer
- WebSocket API
- 📊 OpenTelemetry integration for tracing
- 🏗️ Builder pattern for easy router construction
- 🧩 Modular design with separate core and macro crates
Installation
Run cargo add lambda-lw-http-router
to add the crate to your project or add the following to your Cargo.toml
:
[]
= "0.1.0"
Quick Start
use ;
use ApiGatewayV2httpRequest;
use ;
use Error;
// Define your application state
// Set up the router
define_router!;
// Define route handlers
async
// Lambda function entry point
async
Advanced Usage
Multiple Routers
You can define multiple routers for different event types:
use AlbTargetGroupRequest;
// Define an API Gateway router
define_router!;
// Define an ALB router
define_router!;
// Use specific types for each router
async
async
OpenTelemetry Integration
The router automatically integrates with OpenTelemetry for tracing:
async
Path Parameters
Support for various path parameter patterns:
// Basic parameters
// Multi-segment parameters
// Matches /files/docs/2024/report.pdf
// Multiple parameters
API Documentation
For detailed API documentation, run:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request