doc: Add webhook handling for Elytra Event API with authentication and event routing to read me

This commit is contained in:
claudi 2026-02-23 10:26:02 +01:00
parent b889542590
commit fab2f7f701

View file

@ -165,6 +165,69 @@ See [elytra_client/rest_api/README.md](elytra_client/rest_api/README.md) for com
- Error handling
- Common usage scenarios
## Webhooks (Elytra Event API)
The package includes a subpackage for handling CloudEvents-based webhooks from the Elytra PIM Event API.
### Quick Start
```python
from elytra_client.webhooks import CloudEvent, parse_webhook_payload
# Parse an incoming webhook payload
event = parse_webhook_payload(request.json())
print(f"Event type: {event.eventtype}")
print(f"Object ID: {event.get_object_id()}")
```
### With Authentication Validation
```python
from elytra_client.webhooks import WebhookValidator, BasicAuth
auth = BasicAuth(username="user", password="pass")
validator = WebhookValidator(auth_type="basic", auth=auth)
event = validator.validate_and_parse(
payload=request.json(),
headers=dict(request.headers)
)
```
### Features
- 📨 **CloudEvents Support**: Strongly-typed Pydantic models following the CNCF CloudEvents v1.0 spec
- 🔐 **Flexible Authentication**: Basic, Bearer token, and API Key authentication
- 🔀 **Event Routing**: `SimpleWebhookEventDispatcher` to route events by type and operation to dedicated handlers
- 🔁 **Retry Logic**: Exponential backoff retry policies for reliable webhook delivery
- 🌐 **Framework Integration**: Ready-to-use examples for Flask and FastAPI
### Authentication Methods
```python
# Basic authentication
auth = BasicAuth(username="admin", password="secret")
# Bearer token
auth = BearerAuth(token="eyJhbGciOiJIUzI1NiIs...")
# API Key (custom header)
auth = APIKeyAuth(api_key="sk_live_secret123", header_name="X-API-Key")
```
### Event Types and Operations
Events carry an `EventType` (e.g., `PRODUCT`, `PRODUCT_GROUP`, `PRODUCT_ATTRIBUTE_VALUE`) and an `Operation` (`ADD`, `MODIFY`, `REMOVE`, `LINK`, `UNLINK`).
### Documentation
See [elytra_client/webhooks/README.md](elytra_client/webhooks/README.md) for comprehensive webhook documentation, including:
- Complete API reference
- Authentication details
- Event routing and dispatching
- Retry logic configuration
- Flask and FastAPI integration examples
## API Methods
All methods return Pydantic models with full type validation and IDE autocompletion support.