You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A webhook is a way for an app to provide information to another app about a certain event. The way the two apps communicate is with a simple HTTP request.
8
+
A webhook is a way for an app to provide information to another app about a particular event. The way the two apps communicate is with a simple HTTP request.
9
9
10
-
This package allows you to easily configure and send webhooks in a Laravel app. It has support for [signing calls](https://github.com/spatie/laravel-webhook-server#how-signing-requests-works), [retrying calls and backoff strategies](https://github.com/spatie/laravel-webhook-server#retrying-failed-webhooks).
10
+
This package allows you to configure and send webhooks in a Laravel app easily. It has support for [signing calls](https://github.com/spatie/laravel-webhook-server#how-signing-requests-works), [retrying calls and backoff strategies](https://github.com/spatie/laravel-webhook-server#retrying-failed-webhooks).
11
11
12
12
If you need to receive and process webhooks take a look at our [laravel-webhook-client](https://github.com/spatie/laravel-webhook-client) package.
13
13
@@ -80,7 +80,7 @@ return [
80
80
];
81
81
```
82
82
83
-
By default the package uses queues to retry failed webhook requests. Be sure to setup a real queue other than `sync` in non-local environments.
83
+
By default, the package uses queues to retry failed webhook requests. Be sure to set up a real queue other than `sync` in non-local environments.
84
84
85
85
## Usage
86
86
@@ -90,19 +90,19 @@ This is the simplest way to call a webhook:
90
90
WebhookCall::create()
91
91
->url('https://other-app.com/webhooks')
92
92
->payload(['key' => 'value'])
93
-
->signUsingSecret('sign-using-this-secret')
93
+
->useSecret('sign-using-this-secret')
94
94
->dispatch();
95
95
```
96
96
97
-
This will send a post request to `https://other-app.com/webhooks`. The body of the request will be json encoded version of the array passed to `payload`. The request will have a header called `Signature` that will contain a signature the receiving app can use [to verify](https://github.com/spatie/laravel-webhook-server#how-signing-requests-works) the payload hasn't been tampered with.
97
+
This will send a post request to `https://other-app.com/webhooks`. The body of the request will be JSON encoded version of the array passed to `payload`. The request will have a header called `Signature` that will contain a signature the receiving app can use [to verify](https://github.com/spatie/laravel-webhook-server#how-signing-requests-works) the payload hasn't been tampered with.
98
98
99
-
If the receiving app doesn't respond with a response code starting with `2`, the package will retry calling the webhook after 10 seconds. If that second attempt fails, the package will attempt to call the webhook a final time after 100 seconds. Should that attempt fail the `FinalWebhookCallFailedEvent` will be raised.
99
+
If the receiving app doesn't respond with a response code starting with `2`, the package will retry calling the webhook after 10 seconds. If that second attempt fails, the package will attempt to call the webhook a final time after 100 seconds. Should that attempt fail, the `FinalWebhookCallFailedEvent` will be raised.
100
100
101
101
### How signing requests works
102
102
103
-
When setting up it's common to generate, store and share a secret secret between your app and the app that wants to receive webhooks. Generating the secret could be done with `Illuminate\Support\Str::random()`, but it's really entirely up to you. The package will use the secret to sign a webhook call.
103
+
When setting up, it's common to generate, store, and share a secret between your app and the app that wants to receive webhooks. Generating the secret could be done with `Illuminate\Support\Str::random()`, but it's entirely up to you. The package will use the secret to sign a webhook call.
104
104
105
-
By default the package will add a header called `Signature` that will contain a signature the receiving app can use the payload hasn't been tampered with. This is how that signature is calculated.
105
+
By default, the package will add a header called `Signature` that will contain a signature the receiving app can use the payload hasn't been tampered with. This is how that signature is calculated:
106
106
107
107
```php
108
108
// payload is the array passed to the `payload` method of the webhook
If you want to customize the signing process you can create your own custom signer. A signer is any class that implements `Spatie\WebhookServer\Signer`.
118
+
If you want to customize the signing process, you can create your own custom signer. A signer is any class that implements `Spatie\WebhookServer\Signer`.
119
119
120
120
This is what that interface looks like.
121
121
@@ -130,9 +130,9 @@ interface Signer
130
130
}
131
131
```
132
132
133
-
After creating your signer you can specify it's class name in the `signer` key of the `webhook-server` config file. Your signer will than be used by default in all webhook calls.
133
+
After creating your signer, you can specify it's class name in the `signer` key of the `webhook-server` config file. Your signer will then be used by default in all webhook calls.
134
134
135
-
You can also specify a signer for a specific webhook call
135
+
You can also specify a signer for a specific webhook call:
136
136
137
137
```php
138
138
WebhookCall::create()
@@ -141,13 +141,13 @@ WebhookCall::create()
141
141
->dispatch();
142
142
```
143
143
144
-
If you just want to customize the name of the header you don't need to use a custom signer, but you can just change the value in the `signature_header_name` in the `webhook-server` config file.
144
+
If you want to customize the name of the header, you don't need to use a custom signer, but you can change the value in the `signature_header_name` in the `webhook-server` config file.
145
145
146
146
### Retrying failed webhooks
147
147
148
148
When the app to which we're sending the webhook fails to send a response with a `2xx` status code the package will consider the call as failed. The call will also be considered failed if the remote app doesn't respond within 3 seconds.
149
149
150
-
You can configure that default timeout in the `timeout_in_seconds` key of the `webhook-server` config file. Alternatively you can override the timeout for a specific webhook like this:
150
+
You can configure that default timeout in the `timeout_in_seconds` key of the `webhook-server` config file. Alternatively, you can override the timeout for a specific webhook like this:
151
151
152
152
```php
153
153
WebhookCall::create()
@@ -156,7 +156,7 @@ WebhookCall::create()
156
156
->dispatch();
157
157
```
158
158
159
-
When a webhook call fails we'll retry the call two more times. You can set the default amount of times we just retry the webhook call in the `tries` key of the config file. Alternatively, you can specify the amount of tries for a specific webhook like this:
159
+
When a webhook call fails, we'll retry the call two more times. You can set the default amount of times we retry the webhook call in the `tries` key of the config file. Alternatively, you can specify the number of tries for a specific webhook like this:
160
160
161
161
```php
162
162
WebhookCall::create()
@@ -165,7 +165,7 @@ WebhookCall::create()
165
165
->dispatch();
166
166
```
167
167
168
-
To not hammer the remote app we'll wait some time between each attempts. By default we wait 10 seconds between the first and second attempt, 100 seconds between the third and the fourth, 1000 between the fourth and the fifth and so on. The maximum amount of seconds that we'll wait is 100 000, which is about 27 hours. This behaviour is implemented in the default `ExponentialBackoffStrategy`.
168
+
To not hammer the remote app we'll wait some time between each attempt. By default, we wait 10 seconds between the first and second attempt, 100 seconds between the third and the fourth, 1000 between the fourth and the fifth and so on. The maximum amount of seconds that we'll wait is 100 000, which is about 27 hours. This behavior is implemented in the default `ExponentialBackoffStrategy`.
169
169
170
170
You can define your own backoff strategy by creating a class that implements `Spatie\WebhookServer\BackoffStrategy\BackoffStrategy`. This is what that interface looks like:
171
171
@@ -178,7 +178,7 @@ interface BackoffStrategy
178
178
}
179
179
```
180
180
181
-
You can make your custom strategy the default strategy by specifying it's fully qualified classname in the `backoff_strategy` of the `webhook-server` config file. Alternatively you can specify a strategy for a specific webhook like this.
181
+
You can make your custom strategy the default strategy by specifying it's fully qualified class name in the `backoff_strategy` of the `webhook-server` config file. Alternatively, you can specify a strategy for a specific webhook like this.
182
182
183
183
```php
184
184
WebhookCall::create()
@@ -187,14 +187,14 @@ WebhookCall::create()
187
187
->dispatch();
188
188
```
189
189
190
-
Under the hood the retrying of the webhook calls is implemented using [delayed dispatching](https://laravel.com/docs/master/queues#delayed-dispatching). Amazon SQS only has support for a small maximum delay. If you're using Amazon SQS for your queues, make sure you do not configure the package in away so there is more than 15 minutes between each attempt.
190
+
Under the hood, the retrying of the webhook calls is implemented using [delayed dispatching](https://laravel.com/docs/master/queues#delayed-dispatching). Amazon SQS only has support for a small maximum delay. If you're using Amazon SQS for your queues, make sure you do not configure the package in a way so there are more than 15 minutes between each attempt.
191
191
192
192
193
-
### Customizing the http verb
193
+
### Customizing the HTTP verb
194
194
195
-
By default all webhooks will use the `post` method. You can customize that by specify the http verb you want in the `http_verb` key of the `webhook-server` config file.
195
+
By default, all webhooks will use the `post` method. You can customize that by specifying the HTTP verb you want in the `http_verb` key of the `webhook-server` config file.
196
196
197
-
You can also override the default for a specific call by use the `useHttpVerb` method.
197
+
You can also override the default for a specific call by using the `useHttpVerb` method.
198
198
199
199
```php
200
200
WebhookCall::create()
@@ -205,7 +205,7 @@ WebhookCall::create()
205
205
206
206
### Adding extra headers
207
207
208
-
You can extra headers by adding the to the `headers` key in the `webhook-server` config file. If you want to add extra headers for a specific webhook you can use the `withHeaders` call.
208
+
You can use extra headers by adding them to the `headers` key in the `webhook-server` config file. If you want to add additional headers for a specific webhook, you can use the `withHeaders` call.
209
209
210
210
```php
211
211
WebhookCall::create()
@@ -218,7 +218,7 @@ WebhookCall::create()
218
218
219
219
### Verifying the SSL certificate of the receiving app
220
220
221
-
When using an url that starts with `https://` the package will verify if the SSL certificate of the receiving party is valid. If it is not, we will consider the webhook call failed. We don't recommend this but you can turn off this verification by setting the `verify_ssl` key in the `webhook-server` config file to `false`.
221
+
When using an URL that starts with `https://` the package will verify if the SSL certificate of the receiving party is valid. If it is not, we will consider the webhook call failed. We don't recommend this, but you can turn off this verification by setting the `verify_ssl` key in the `webhook-server` config file to `false`.
222
222
223
223
You can also disable the verification per webhook call with the `doNotVerifySsl` method.
224
224
@@ -231,7 +231,7 @@ WebhookCall::create()
231
231
232
232
### Adding meta information
233
233
234
-
You can add extra meta information to the webhook. This meta information will not be transmitted, it will only be used to pass to [the events this package fires](#events).
234
+
You can add extra meta information to the webhook. This meta information will not be transmitted, and it will only be used to pass to [the events this package fires](#events).
235
235
236
236
This is how you can add meta information:
237
237
@@ -244,7 +244,7 @@ WebhookCall::create()
244
244
245
245
### Adding tags
246
246
247
-
If you're using [Laravel Horizon](https://laravel.com/docs/5.8/horizon) for your queues you'll be happy to know that we support [tags](https://laravel.com/docs/5.8/horizon#tags).
247
+
If you're using [Laravel Horizon](https://laravel.com/docs/5.8/horizon) for your queues, you'll be happy to know that we support [tags](https://laravel.com/docs/5.8/horizon#tags).
248
248
249
249
To add tags to the underlying job that'll perform the webhook call, simply specify them in the `tags` key of the `webhook-server` config file or use the `withTags` method:
250
250
@@ -259,13 +259,13 @@ WebhookCall::create()
259
259
260
260
The package fires these events:
261
261
-`WebhookCallSucceededEvent`: the remote app responded with a `2xx` response code.
262
-
-`WebhookCallFailedEvent`: the remote app responded with a non `2xx` response code or it did not respond at all
262
+
-`WebhookCallFailedEvent`: the remote app responded with a non `2xx` response code, or it did not respond at all
263
263
-`FinalWebhookCalledFailedEvent`: the final attempt to call the webhook failed.
264
264
265
265
All these events have these properties:
266
266
267
267
-`httpVerb`: the verb used to perform the request
268
-
-`webhookUrl`: the url to where the request was sent
268
+
-`webhookUrl`: the URL to where the request was sent
269
269
-`payload`: the used payload
270
270
-`headers`: the headers that were sent. This array includes the signature header
271
271
-`meta`: the array of values passed to the webhook with [the `meta` call](#adding-meta-information)
@@ -289,11 +289,11 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
289
289
290
290
### Security
291
291
292
-
If you discover any securityrelated issues, please email [email protected] instead of using the issue tracker.
292
+
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
293
293
294
294
## Postcardware
295
295
296
-
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
296
+
You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
297
297
298
298
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
299
299
@@ -306,7 +306,7 @@ We publish all received postcards [on our company website](https://spatie.be/en/
306
306
307
307
## Support us
308
308
309
-
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
309
+
Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
310
310
311
311
Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie).
312
312
All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
0 commit comments