Skip to content

Commit

Permalink
docs: update docs with HTTP example
Browse files Browse the repository at this point in the history
  • Loading branch information
danihodovic committed Oct 20, 2023
1 parent f849055 commit 8bc55d5
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ Django has a built-in signal system which allows programmers to schedule functio
model changes. django-webhook leverages the signal system together with Celery to send HTTP requests
when models change.

Suppose we have a User model
```python
class User(models.Model):
name = models.CharField(max_length=50)
age = models.PositiveIntegerField()
```

If a webhook is configured, any time the above model is created, updated or deleted django-webhook
will send an outgoing HTTP request to a third party:

```
POST HTTP/1.1
host: webhook.site
user-agent: python-urllib3/2.0.3
django-webhook-uuid: 5e2ee3ba-905e-4360-94bf-18ef21c0e844
django-webhook-signature-v1:
django-webhook-request-timestamp: 1697818014
{
"topic": "users.User/create",
"object": {
"id": 3,
"name": "Dani Doo",
"age": 30
},
"object_type": "users.User",
"webhook_uuid": "5e2ee3ba-905e-4360-94bf-18ef21c0e844"
}
```

### 🔥 Feautures
- Automatically sends webhooks on model changes
- Leverages Celery for processing
Expand Down
41 changes: 41 additions & 0 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@ Django has a built-in signal system which allows programmers to schedule functio
model changes. django-webhook leverages the signal system together with Celery to send HTTP requests
when models change.

Suppose we have a User model:
```python
class User(models.Model):
name = models.CharField(max_length=50)
age = models.PositiveIntegerField()
```

If a webhook is configured, any time the above model is created, updated or deleted django-webhook
will send an outgoing HTTP request to a third party:

```
POST HTTP/1.1
host: webhook.site
user-agent: python-urllib3/2.0.3
django-webhook-uuid: 5e2ee3ba-905e-4360-94bf-18ef21c0e844
django-webhook-signature-v1:
django-webhook-request-timestamp: 1697818014
{
"topic": "users.User/create",
"object": {
"id": 3,
"name": "Dani Doo",
"age": 30
},
"object_type": "users.User",
"webhook_uuid": "5e2ee3ba-905e-4360-94bf-18ef21c0e844"
}
```

### 🔥 Feautures
- Automatically sends webhooks on model changes
- Leverages Celery for processing
- Webhook authentication using HMAC
- Retries with exponential backoff
- Admin integration
- Audit log with past webhook events
- Protection from replay attacks


### 📜 Table of Contents
```{toctree}
install
```
28 changes: 26 additions & 2 deletions docs/source/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ Configure an outgoing webhook for one of your models

Set the topic to be triggered on create and update for your model.
```python
>>> topics = [WebhookTopic.objects.get(name="core.Product/create"), WebhookTopic.objects.get(name="core.Product/update")]
>>> topics = [
WebhookTopic.objects.get(name="core.Product/create"),
WebhookTopic.objects.get(name="core.Product/update")
]
>>> webhook.topics.set(topics)
```

Expand All @@ -78,6 +81,27 @@ Finally create a new Product instance to trigger the webhook.
>>> Product.objects.create(name="test")
```

Visit the page for your unique webhook where you can expect the incoming HTTP request.
django-webhook should send an outgoing HTTP request in the following format:

```
POST HTTP/1.1
host: webhook.site
user-agent: python-urllib3/2.0.3
django-webhook-uuid: 5e2ee3ba-905e-4360-94bf-18ef21c0e844
django-webhook-signature-v1:
django-webhook-request-timestamp: 1697818014
{
"topic": "core.Product/create",
"object": {
"id": 3,
"name": "test",
},
"object_type": "core.Product",
"webhook_uuid": "5e2ee3ba-905e-4360-94bf-18ef21c0e844"
}
```

Visit [the page](https://webhook.site) for your unique webhook where you can inspect the incoming HTTP request.

![incoming-webhook-example](webhook-site-incoming-webhook.png)

0 comments on commit 8bc55d5

Please sign in to comment.