2020-01-14 15:57:45 +03:00
|
|
|
.. meta::
|
|
|
|
:description: Set up a first event trigger with Hasura
|
|
|
|
:keywords: hasura, docs, start, event trigger
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
.. _first_event_trigger:
|
|
|
|
|
2018-09-11 14:11:24 +03:00
|
|
|
Setting up your first event trigger
|
|
|
|
===================================
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2019-10-26 07:07:37 +03:00
|
|
|
You can use Hasura to setup event triggers that call configured webhooks whenever specific database events occur.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
Let's create a sample event trigger with https://httpbin.org as our simple webhook.
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
Create a table
|
|
|
|
--------------
|
2018-09-11 14:11:24 +03:00
|
|
|
Head to the Hasura console, navigate to ``Data -> Create table`` and create a sample table called ``profile`` with
|
|
|
|
the following columns:
|
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
.. code-block:: sql
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
profile (
|
|
|
|
id INT PRIMARY KEY,
|
|
|
|
name TEXT
|
|
|
|
)
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-05-05 06:52:08 +03:00
|
|
|
.. thumbnail:: /img/graphql/manual/getting-started/create-profile-table.png
|
2020-01-08 16:20:18 +03:00
|
|
|
:alt: Create a table
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
Setup an event trigger
|
|
|
|
----------------------
|
|
|
|
In the Hasura console, navigate to ``Events -> Create trigger`` and:
|
|
|
|
|
2018-10-04 07:09:47 +03:00
|
|
|
1. Enter trigger name as ``echo``.
|
|
|
|
2. Select table ``profile`` from the table dropdown.
|
|
|
|
3. Select operations: ``insert``, ``update`` and ``delete``.
|
|
|
|
4. Enter webhook URL as: ``https://httpbin.org/post``.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-05-05 06:52:08 +03:00
|
|
|
.. thumbnail:: /img/graphql/manual/getting-started/create-event-trigger.png
|
2020-01-08 16:20:18 +03:00
|
|
|
:alt: Set up an event trigger
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-10-26 07:07:37 +03:00
|
|
|
This sets up our webhook ``https://httpbin.org/post`` to receive database changes on an insert, update and delete on
|
2018-09-11 14:11:24 +03:00
|
|
|
``profile`` table.
|
|
|
|
|
|
|
|
|
|
|
|
Watch the trigger in action
|
|
|
|
---------------------------
|
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
1. Insert some sample data into the ``profile`` table using the ``Insert Row`` tab.
|
2018-09-11 14:11:24 +03:00
|
|
|
2. Now navigate to the ``Events`` tab and click on the ``echo`` trigger in the left sidebar.
|
|
|
|
3. Expand the details of an event to see the response from the webhook.
|
|
|
|
|
2020-05-05 06:52:08 +03:00
|
|
|
.. thumbnail:: /img/graphql/manual/getting-started/trigger-events.png
|
2020-01-08 16:20:18 +03:00
|
|
|
:alt: Trigger in action
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
Next steps
|
|
|
|
----------
|
|
|
|
|
|
|
|
Read more about:
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
- :ref:`Event triggers <event_triggers>`
|