Skip to main content

baukit_http/
routing.rs

1use axum::Router;
2
3use crate::{ApiError, HttpOptions, middleware::layers};
4
5/// Finalizes a public router with standard 404/405 envelopes and HTTP layers.
6///
7/// Call this once after defining and merging all product routes. Unmatched paths
8/// return `not_found`, unsupported methods return `method_not_allowed`, and both
9/// responses include the request ID installed by the lifecycle middleware.
10pub fn finalize<S>(router: Router<S>, options: HttpOptions) -> Router<S>
11where
12    S: Clone + Send + Sync + 'static,
13{
14    layers(
15        router
16            .fallback(route_not_found)
17            .method_not_allowed_fallback(method_not_allowed),
18        options,
19    )
20}
21
22async fn route_not_found() -> ApiError {
23    ApiError::not_found("Route not found")
24}
25
26async fn method_not_allowed() -> ApiError {
27    ApiError::method_not_allowed()
28}