Sending webhooks | laravel-webhook-server-rust | Spatie       

 SPATIE  

laravel-webhook-server-rust
===========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-server-rust](https://spatie.be/docs/laravel-webhook-server-rust/v1)  Sending webhooks

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-server-rust/v1) 

  Sending webhooks    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server-rust/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server-rust/v1/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server-rust/v1/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server-rust/v1/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server-rust/v1/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing-webhooks)
- [ Upgrading ](https://spatie.be/docs/laravel-webhook-server-rust/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-server-rust/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-server-rust/v1/support-us)

 Sending webhooks
================

###  On this page 

1. [ Send a JSON payload ](#content-send-a-json-payload)
2. [ Send synchronously or conditionally ](#content-send-synchronously-or-conditionally)
3. [ Change the HTTP verb and headers ](#content-change-the-http-verb-and-headers)
4. [ Send a raw body ](#content-send-a-raw-body)
5. [ Delivery IDs and timestamps ](#content-delivery-ids-and-timestamps)
6. [ Metadata and tags ](#content-metadata-and-tags)

Send a JSON payload
-----------------------------------------------------------------------------------------------------------------

```
use serde_json::json;
use spatie_laravel_webhook_server::WebhookCall;

WebhookCall::create()
    .url("https://other-app.com/webhooks")
    .payload(json!({"order_id": 123}))
    .use_secret("your-shared-secret")
    .dispatch().await?;
```

The package validates the URL, headers, retry settings and signing secret before dispatch. It prepares JSON once and keeps the same bytes and signature on every retry. `prepare()` returns the serializable `PreparedWebhook` without dispatching it. Secrets do not enter that value or the queue payload.

Send synchronously or conditionally
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Use `dispatch_sync().await` for one immediate attempt. Synchronous delivery never waits or retries. The methods `dispatch_if(bool)`, `dispatch_unless(bool)`, `dispatch_sync_if(bool)` and `dispatch_sync_unless(bool)` skip preparation and dispatch when their condition excludes the call.

Change the HTTP verb and headers
--------------------------------------------------------------------------------------------------------------------------------------------------------

Use `use_http_verb("PUT")` and `with_header("X-Source", "billing")`. Headers override earlier values case-insensitively. Global defaults live in `Config.http_verb` and `Config.headers`. Standard and custom methods are accepted.

GET sends a JSON object's fields as query parameters while signing its serialized JSON representation, not the empty wire body. Use scalar query values supported by Laravel's query serializer; nested JSON query objects are not supported. A receiver must reproduce that JSON representation to verify GET signatures. Prefer POST for signed payloads.

Send a raw body
-----------------------------------------------------------------------------------------------------

```
use spatie_laravel_webhook_server::{Config, WebhookCall};

let webhook = WebhookCall::with_config(Config::default())
    .url("https://other-app.com/webhooks")
    .send_raw_body(b"<root>content</root>".to_vec())
    .with_header("Content-Type", "application/xml")
    .use_secret("your-shared-secret")
    .prepare()?;

assert_eq!(webhook.body, b"<root>content</root>");
```

`send_raw_body` accepts arbitrary bytes, including non-UTF-8 data. It does not JSON-encode the body. Listeners receive `Payload::Raw` or `Payload::Json` as appropriate.

Delivery IDs and timestamps
-----------------------------------------------------------------------------------------------------------------------------------------

Every call starts with a UUID. Read it with `get_uuid()` or set your own using `uuid("order-123")`. The `Webhook-Id` header remains unchanged across retries. An explicit header of that name takes precedence regardless of casing. Rename or disable it using `with_webhook_id_header(Some("X-Delivery-Id".into()))` or `with_webhook_id_header(None)`.

`use_timestamp(true)` adds a Unix timestamp freshly on each attempt. `Config.timestamp_header_name` renames that header. The default signer authenticates the body only, not the timestamp or ID. For replay protection, place a timestamp in the signed payload, validate its age on the receiver, and make processing idempotent.

Metadata and tags
-----------------------------------------------------------------------------------------------------------

Use `meta(json!({"order_id": 123}))` for local context and `with_tags(vec!["billing".into()])` for tags. Both remain on the queued job and events; neither is added to the outgoing HTTP body or headers. This package does not install Horizon or a metrics backend.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
