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
- 📊 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.1"
Quick Start
use ;
use ApiGatewayV2httpRequest;
use ;
use ;
use Arc;
// Define your application state
// Set up the router
define_router!;
// Define route handlers
async
// Lambda function entry point
async
OpenTelemetry Integration
The router automatically integrates with OpenTelemetry for tracing, adding semantic http attributes to the span and setting the span name to the route path. It also support setting additional attributes to the spanas shown in the following example:
async
Path Parameters
Support for various path parameter patterns:
// Basic parameters
async
// Multi-segment parameters
// Matches /files/docs/2024/report.pdf
async
// Multiple parameters
async
API Documentation
For detailed API documentation, run:
License
This project is licensed under the MIT License - see the LICENSE file for details.