Webhooks
Deta Micros make it extremely easy to deploy webhook servers.
Each Deta Micro has a unique HTTPS endpoint which can be used as the webhook URL.
You can use your favorite web application framework for your webhook server.
The guide assumes you have already signed up for Deta and have the Deta CLI installed.
- JavaScript
- Python
We are going to use express
with our Deta Micro and deploy a simple nodejs
webhook server.
Create a directory
express-webhook
and change the current directory to it.Create an empty
index.js
file (we will add the code that handles the logic later).Initialize a
nodejs
project withnpm init
You can skip the
-y
flag, if you want to fill the details about the package interactively through npm's wizard.Install
express
locally for your project.Create a new
nodejs
micro withdeta new
. This will create a newnodejs
micro for you and automatically installexpress
as a dependency.Your micro's
endpoint
will be different from the output shown above. Thisendpoint
will be the webhook URL when you set up your webhooks.You can also see that the
http_auth
isenabled
by default. We will disable thehttp_auth
so that webhook events can be sent to the micro.note
Usually for security, a secret token is shared between the sender and the receiver and a hmac signature is calculated from the payload and the shared secret. The algorithm to calculate the signature varies based on the sender. You should consult the documentation of how the signature is calculated for the system you are receiving events from.
Add a
POST
route toindex.js
. Most webhook callbacks send aPOST
request on the webhook URL with the payload containing information about the event that triggered the webhook.Open
index.js
and add the handler to handle webhook events.Deploy your changes with
deta deploy
.
Your micro will now trigger on POST
requests to the micro's endpoint. Use your micro's endpoint as the webhook URL when you set up your webhooks elsewhere.
In order to see the logs when the webhook is triggered, you can use deta visor
to see real-time logs of your application. You can also replay your webhook events from deta visor
to debug any issues.
You can open your visor page with the command deta visor open
from the cli.
We are going to use fastapi
with our Deta Micro and deploy a simple python
webhook server.
Create a directory
fastapi-webhook
and change the current directory to it.Create an empty
main.py
file (we will add the code that handles the logic later).Create a
requirements.txt
file and addfastapi
as a dependency.Create a new
python
micro withdeta new
. This will create a newpython
micro for you and automatically installfastapi
as a dependency.Your micro's
endpoint
will be different from the output shown above. Thisendpoint
will be the webhook URL when you set up your webhooks.You can also see that the
http_auth
isenabled
by default. We will disable thehttp_auth
so that webhook events can be sent to the micro.note
Usually for security, a secret token is shared between the sender and the receiver and a hmac signature is calculated from the payload and the shared secret. The algorithm to calculate the signature varies based on the sender. You should consult the documentation of how the signature is calculated for the system you are receiving events from.
Add a
POST
route tomain.py
. Most webhook callbacks send aPOST
request on the webhook URL with the payload containing information about the event that triggered the webhook.Open
main.py
and add the handler to handle webhook events.Deploy your changes with
deta deploy
.
Your micro will now trigger on POST
requests to the micro's endpoint. Use your micro's endpoint as the webhook URL when you set up your webhooks elsewhere.
In order to see the logs of when the webhook is triggered, you can use deta visor
to see real-time logs of your application. You can also replay your webhook events from deta visor
to debug any issues.
You can open your visor page with the command deta visor open
from the cli.