aws_lambda_router/lib.rs
1//! # AWS Lambda Router
2//!
3//! A lightweight, Express-like REST API routing framework for AWS Lambda functions
4//! behind CloudFront with support for middleware, authentication, and CORS.
5//!
6//! ## Features
7//! - Express-like routing with path parameters
8//! - Middleware support (auth, logging, CORS, etc.)
9//! - Automatic CORS preflight handling
10//! - Type-safe request/response handling
11//! - Path parameter extraction
12//! - Query string parsing
13//! - JSON body parsing
14//! - Error handling with proper HTTP status codes
15//!
16//! ## Example
17//! ```rust,ignore
18//! use aws_lambda_router::{Router, Request, Response, Context, handler};
19//! use lambda_runtime::Error;
20//! use serde_json::json;
21//!
22//! async fn get_user(req: Request, ctx: Context) -> aws_lambda_router::Result<Response> {
23//! let user_id = req.path_param("userId").unwrap_or(&"unknown".to_string()).clone();
24//! Ok(Response::ok(json!({
25//! "userId": user_id,
26//! "name": "John Doe"
27//! })))
28//! }
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<(), Error> {
32//! let mut router = Router::new();
33//! router.get("/api/users/:userId", handler!(get_user));
34//! lambda_runtime::run(router.into_service()).await
35//! }
36//! ```
37
38pub mod cors;
39pub mod error;
40pub mod matcher;
41pub mod middleware;
42pub mod request;
43pub mod response;
44pub mod router;
45
46// Re-export main types
47pub use cors::CorsConfig;
48pub use error::{Result, RouterError};
49pub use matcher::PathMatcher;
50pub use middleware::{Middleware, Next};
51pub use request::{Context, Request};
52pub use response::Response;
53pub use router::{Handler, HandlerFn, Router};
54
55// The handler! macro is already exported via #[macro_export] in router.rs