Skip to content

Commit

Permalink
ACP-2626 Added docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
stereomon committed Jul 16, 2024
1 parent 8a52440 commit f2b63e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ Provides SyncAPI and AsyncAPI schema files and the needed code to make the Mini-
composer require spryker/app-webhook
```

### Configure

#### App Identifier

config/Shared/config_default.php

```
use Spryker\Shared\AppWebhook\AppConstants;
$config[AppConstants::APP_IDENTIFIER] = getenv('APP_IDENTIFIER') ?: 'hello-world';
```

### Testing the AppWebhook

Expand All @@ -36,3 +25,45 @@ With these commands you've set up the AppWebhook and can start the tests
vendor/bin/codecept build
vendor/bin/codecept run
```

# Documentation

# High-Level Architecture

[<img alt="AppWebhook High-Level Architecture" width="auto" src="docs/images/app-webhook-high-level-architecture.svg" />](https://docs.spryker.com/)


## Features

### Handling of external Webhook requests
This package provides all functionality that is needed to receive webhook requests from external applications. This package basically does nothing than providing a stack to add webhook handler from any package that has to deal with webhooks.

When a webhook is received but no handler is executed a failed response will be returned to the caller.

When a webhook was handled a successful response will be returned to the caller.

# Extension

## Glue
Glue offers the following extension points

- `\Spryker\Glue\AppWebhookBackendApi\Plugin\AppWebhookBackendApi\GlueRequestWebhookMapperPluginInterface`

### GlueRequestWebhookMapperPluginInterface
This plugin interface can be used in your application to map some information from the request to the `WebhookRequestTransfer` object which you can use to forward request data like headers into your application. You can also extract information out of the request body and set attributes on the `WebhookRequestTransfer`. For this, you need to add your attributes to the `WebhookRequestTransfer` as you already know from SCOS implementations Create, use, and extend the transfer objects | Spryker Documentation

## Zed
Zed offers the following extension points:

- `\Spryker\Zed\AppWebhook\Dependency\Plugin\WebhookHandlerPluginInterface`

### WebhookHandlerPluginInterface
This plugin needs to be implemented in your application which should handle specific webhook requests. The plugin offers two methods for you:

- `canHandle(WebhookRequestTransfer $webhookRequestTransfer)`
- `handle(WebhookRequestTransfer $webhookRequestTransfer, WebhookResponseTransfer $webhookResponseTransfer)`

The `canHandle()` method returns a boolean indicating if this plugin can handle the current request. F.e. you have two different handlers in your application, one can handle foo events and the other one can handle bar events. You can combine the

`GlueRequestWebhookMapperPluginInterface` that extracts the event name from the request and sets it in the `WebhookRequestTransfer` e.g. as eventName your `WebhookHandlerPluginInterface::canHandle()` can make use of this value and returns the boolean to indicate this plugin can handle the current request or not.

4 changes: 4 additions & 0 deletions docs/images/app-webhook-high-level-architecture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f2b63e0

Please sign in to comment.