pub struct WebhookSender { /* private fields */ }Expand description
High-level webhook sender that signs and delivers payloads using the Standard Webhooks protocol.
Clone-cheap: the inner state is wrapped in Arc.
Implementations§
Source§impl WebhookSender
impl WebhookSender
Sourcepub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
pub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
Override the default User-Agent header sent with every request.
The value must be a valid HTTP header value (visible ASCII only, no control characters). Invalid values are silently ignored.
§Panics
Panics if called after the sender has been cloned. Call this immediately
after WebhookSender::new before handing clones to other tasks.
Sourcepub fn default_client() -> Self
pub fn default_client() -> Self
Convenience constructor using a default reqwest::Client with a
30-second timeout.
Sourcepub async fn send(
&self,
url: &str,
id: &str,
body: &[u8],
secrets: &[&WebhookSecret],
) -> Result<WebhookResponse>
pub async fn send( &self, url: &str, id: &str, body: &[u8], secrets: &[&WebhookSecret], ) -> Result<WebhookResponse>
Send a webhook following the Standard Webhooks protocol.
Signs the payload with every secret in secrets (supports key rotation)
and POSTs to url with the three Standard Webhooks headers:
webhook-id, webhook-timestamp, and webhook-signature.
url: the endpoint to POST toid: unique message ID for idempotency (e.g.msg_<ulid>)body: raw request body (typically JSON)secrets: one or more signing secrets; at least one is required
§Errors
Returns Error when:
secretsis empty (400 Bad Request)idis empty (400 Bad Request)urlis not a valid URI (400 Bad Request)- the HTTP request fails (network error, timeout, etc.)