| Crates.io | axum-standardwebhooks |
| lib.rs | axum-standardwebhooks |
| version | 1.0.0 |
| created_at | 2025-03-14 17:56:37.013618+00 |
| updated_at | 2025-03-14 17:56:37.013618+00 |
| description | Axum extractor that verifies signature for Standard Webhooks |
| homepage | |
| repository | https://github.com/dndx/axum-standardwebhooks |
| max_upload_size | |
| id | 1592551 |
| size | 32,496 |
A library providing Axum extractors for validating webhooks according to the Standard Webhooks specification.
FromRequestAdd the dependency to your Cargo.toml:
[dependencies]
axum-standardwebhooks = "1"
use axum::{Router, routing::post, Json};
use axum_standardwebhooks::{StandardWebhook, SharedWebhook, Webhook};
use serde_json::Value;
use std::sync::Arc;
use axum::extract::FromRef;
async fn webhook_handler(StandardWebhook(Json(payload)): StandardWebhook<Json<Value>>) -> String {
// The webhook signature has been verified, and we can safely use the payload
format!("Received webhook: {}", payload)
}
#[derive(Clone)]
struct AppState {
webhook: SharedWebhook,
}
impl FromRef<AppState> for SharedWebhook {
fn from_ref(state: &AppState) -> Self {
state.webhook.clone()
}
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/webhooks", post(webhook_handler))
.with_state(AppState {
webhook: SharedWebhook::new(Webhook::new("whsec_C2FVsBQIhrscChlQIMV+b5sSYspob7oD").unwrap()),
});
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.