Skip to content

Commit

Permalink
docs: update readme with webhook listener info
Browse files Browse the repository at this point in the history
  • Loading branch information
vinyguedess committed May 8, 2020
1 parent fa932b5 commit 27b5b73
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,53 @@ don't need to be waited for the main process.
print("I'm gonna be executed on another thread")
>>> disthread("event.name")
Webhook listener
================
It's possible declare webhook rules to be dispatched as an inside event.
This webhook events can be a powerful tool for communicating to third-party
clients that an event is ended.

**Listener rules**:

- **route**
- **type**: str
- **description**: API route
- **required**
- **callback**
- **type**: callable/function
- **description**: Receives request response object if needed

When **dispatch** or **disthread** is called is possible define some attributes to
be sent in the external API call.

**Attributes**:

- **data**
- **type**: dict
- **description**: JSON body
- **headers**
- **type**: dict
- **description**: Dictionary declaring headers to be sent

**Example**:

.. code :: python
from onany import dispatch, listener
def event_name_webhook_response(response):
if response.status_code == 200:
print("My hook listener worked")
listener("event.name", {
"route": "https://my.api/hooks",
"callback": event_name_webhook_response
})
>>> dispatch("event.name", data={
"some": "payload",
"I": "wanna",
"send": "to",
"hooked": "api"
})

0 comments on commit 27b5b73

Please sign in to comment.