From 02f6e4156d6b4c335a9b5df8d74647ac2e5025bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Tue, 20 Oct 2020 13:26:36 +0200 Subject: [PATCH] better readme introduction --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 39195b9..d71af41 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,8 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/viezel/webhooks.svg?style=flat-square)](https://packagist.org/packages/viezel/webhooks) [![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/viezel/webhooks/run-tests?label=tests)](https://github.com/viezel/webhooks/actions?query=workflow%3Arun-tests+branch%3Amaster) - Simple and clear implementation of Webhooks. - ## Installation You can install the package via composer: @@ -29,7 +27,7 @@ Route::middleware('auth:api')->prefix('api')->as('webhooks.api.')->group(functio Route::get('hooks', Viezel\Webhooks\Controllers\API\ListWebhooks::class)->name('list'); Route::get('hooks/events', Viezel\Webhooks\Controllers\API\ListWebhookEvents::class)->name('events'); Route::post('hooks', Viezel\Webhooks\Controllers\API\CreateWebhook::class)->name('create'); - Route::post('hooks/{id}', Viezel\Webhooks\Controllers\API\DeleteWebhook::class)->name('delete'); + Route::delete('hooks/{id}', Viezel\Webhooks\Controllers\API\DeleteWebhook::class)->name('delete'); }); ``` @@ -72,6 +70,45 @@ class PostUpdatedEvent implements ShouldDeliverWebhooks } ``` +Next you need to register all your events with the `WebhookRegistry`. +This is typically done in the boot method of a ServiceProvider. + +```php +public function boot() +{ + WebhookRegistry::listen(PostUpdatedEvent::class); +} +``` + +To check everything works as expected, go visit the webhooks events route. The default route is: `/api/hooks/events`. +It depends how you register the webhook routes. + +### List available webhooks events + +GET https://myapp.test/api/hooks/events + +### List registered webhooks + +GET https://myapp.test/api/hooks + +### Register a webhook + +POST https://myapp.test/api/hooks + +```json +{ + "events": [ + "post:updated" + ], + "url": "https://another-app.com/some/callback/route" +} +``` + +### Delete a webhook + +DELETE https://myapp.test/api/hooks/{id} + + ## Testing ```bash