Expand description
Axum integration for webhooksmith.
§Verifying incoming webhooks
Add the WebhookSecretLayer to your router, then use the
VerifiedWebhook extractor in any handler. It automatically verifies the
HMAC-SHA256 signature, rejects stale timestamps, and gives you the raw JSON
body. Use TypedWebhook<T> if you want automatic deserialization.
use axum::{Router, routing::post, http::StatusCode};
use webhooksmith_axum::{WebhookSecretLayer, VerifiedWebhook, TypedWebhook};
use serde::Deserialize;
#[derive(Deserialize)]
struct OrderCreated { order_id: u64 }
async fn handle_raw(VerifiedWebhook(body): VerifiedWebhook) -> StatusCode {
tracing::info!(event_type = %body.event_type, "received webhook");
StatusCode::OK
}
async fn handle_typed(TypedWebhook(order): TypedWebhook<OrderCreated>) -> StatusCode {
tracing::info!(order_id = order.order_id, "order created");
StatusCode::OK
}
let app: Router = Router::new()
.route("/webhooks", post(handle_raw))
.route("/orders", post(handle_typed))
.layer(WebhookSecretLayer::new("your-signing-secret"));Structs§
- Typed
Webhook - Axum extractor that verifies the webhooksmith signature and deserializes the
JSON body into
T. - Verified
Webhook - Axum extractor that verifies the webhooksmith HMAC-SHA256 signature and returns the raw JSON payload.
- Webhook
Payload - The verified and parsed content of an incoming webhook request.
- Webhook
Secret Layer - Tower middleware layer that injects the webhook signing secret into request extensions so extractors can verify signatures.
- Webhook
Secret Service - The middleware service produced by
WebhookSecretLayer.
Enums§
- Webhook
Rejection - Rejection type returned when signature verification fails.