Skip to main content

Crate webhooksmith_axum

Crate webhooksmith_axum 

Source
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§

TypedWebhook
Axum extractor that verifies the webhooksmith signature and deserializes the JSON body into T.
VerifiedWebhook
Axum extractor that verifies the webhooksmith HMAC-SHA256 signature and returns the raw JSON payload.
WebhookPayload
The verified and parsed content of an incoming webhook request.
WebhookSecretLayer
Tower middleware layer that injects the webhook signing secret into request extensions so extractors can verify signatures.
WebhookSecretService
The middleware service produced by WebhookSecretLayer.

Enums§

WebhookRejection
Rejection type returned when signature verification fails.

Functions§

admin
Build an axum Router exposing admin endpoints backed by engine.