8 releases (5 breaking)
0.6.0 | Aug 18, 2024 |
---|---|
0.5.0 | Aug 18, 2024 |
0.4.0 | Aug 14, 2024 |
0.3.2 | Aug 19, 2023 |
0.1.0 | Aug 18, 2023 |
#12 in #query-parameters
9KB
99 lines
Use something like:
use axum::error_handling::HandleErrorLayer;
use axum::Router;
use hmac_predicate::HmacQueryParamValidator;
use reqwest::StatusCode;
use tower::{BoxError, ServiceBuilder};
#[tokio::main]
async fn main() {
let predicate: HmacQueryParamValidator = HmacQueryParamValidator {
key: API_SECRET.to_string(),
};
let builder = ServiceBuilder::new()
.layer(HandleErrorLayer::new(handle_error))
.filter(predicate);
let app = Router::new()
.route("/", get(handler))
.layer(builder);
}
async fn handle_error(err: BoxError) -> (StatusCode, String) {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled internal error: {}", err),
)
}
Dependencies
~2.2–3MB
~59K SLoC