pub trait WebhookHandler: Send + Sync {
// Required method
fn handle<'a>(
&'a self,
context: WebhookContext,
payload: Value,
) -> BoxFuture<'a, Result<(), WebhookError>>;
}Expand description
Trait for handling incoming webhook requests.
Implement this trait to define custom webhook handling logic.
Handlers are invoked by WebhookRegistry::process()
after webhook signature verification succeeds.
§Thread Safety
Handlers must be Send + Sync to allow sharing across async tasks.
§Example
use shopify_sdk::webhooks::{WebhookHandler, WebhookContext, WebhookError, BoxFuture};
use serde_json::Value;
struct OrderCreatedHandler;
impl WebhookHandler for OrderCreatedHandler {
fn handle<'a>(
&'a self,
context: WebhookContext,
payload: Value,
) -> BoxFuture<'a, Result<(), WebhookError>> {
Box::pin(async move {
// Access webhook metadata
if let Some(shop) = context.shop_domain() {
println!("Received webhook from: {}", shop);
}
// Process the payload
if let Some(order_id) = payload.get("id") {
println!("Order created: {}", order_id);
}
Ok(())
})
}
}