pub struct Router<State, E>{ /* private fields */ }
Expand description
The main router type that handles HTTP requests and dispatches them to handlers.
The router matches incoming requests against registered routes and executes the corresponding handlers. It supports path parameters and different HTTP methods.
§Type Parameters
State
- The type of the application state shared across handlersE
- The Lambda event type (must implementRoutableHttpEvent
)
§Examples
use lambda_lw_http_router_core::{Router, RouteContext};
use serde_json::{json, Value};
use lambda_runtime::Error;
use aws_lambda_events::apigw::ApiGatewayV2httpRequest;
#[derive(Clone)]
struct State {}
let mut router: Router<State, ApiGatewayV2httpRequest> = Router::new();
router.register_route("GET", "/hello/{name}", |ctx| async move {
let name = ctx.params.get("name").map_or("World", String::as_str);
Ok(json!({ "message": format!("Hello, {}!", name) }))
});
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<State, E> Freeze for Router<State, E>
impl<State, E> !RefUnwindSafe for Router<State, E>
impl<State, E> Send for Router<State, E>
impl<State, E> Sync for Router<State, E>
impl<State, E> Unpin for Router<State, E>
impl<State, E> !UnwindSafe for Router<State, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more