Webhooks Explained: What is a Webhook?
What are webhooks? A webhook automates the sending of information to another application when an event occurs. The message is delivered in the form of a unique URL that can be parsed by other applications.
Let me get the conceptual difference of an API vs a Webhook clear for you with a small example:
You have two assistants at your office. Both have the same set of responsibilities between them.
The first assistant has all the data ready for you at all times. She provides you with any data that you need, the moment you request it.
The second assistant, also has all the data ready. But she keeps you updated with relevant information, without your intervention.
Both of them are able to handle information really well for us. But the first one gives us the required information when requested. The second one keeps us updated with relevant information as and when it comes up.
So what does this all mean?
- The first assistant is an example of an API. It provides the data only when requested.
- The second assistant is an example of a webhook. We let it know what data is relevant, right in the beginning, and it keeps us updated with the data without requests.
With the concept of a webhook and API clear, let's answer the technical question now.
What is a Webhook?
A Webhook is an event-based trigger that helps applications to communicate among themselves. All of this can be done automatically once it's set up.
They listen to the webhook event that occurs on the page or platform and return data from the event. Though this can be done after the proper webhook integration within your custom application
They allow you to create specific URL POSTs with a unique identifier holding the required webhook request data that are passed to the internal applications and databases for processing. The webhook URL can be changed based on the specific event type that is being passed to the web application.
How to Use Webhooks?
The concept of a webhook is simple once you understand that the fundamental process involves passing data by adding parameters to the Webhook URL. You also need to have a webhook subscription which can be provided by the SaaS webhook provider who enables webhooks for you.
Now how do you create those parameters and pass the Webhook URL to the desired application for processing?
Before we dive into that, let's understand how webhooks are passed.
How are Webhooks passed between applications?
This is made possible with the HTTP POST request. A POST request allows passing data between applications. The data can be sent as a JSON object or in XML format both of which are accepted by all programming languages for data processing.
On your website, a POST request can be generated in multiple ways:
- HTML forms
What data can be passed in JSON or XML formats?
Let's quickly have a look at what JSON and XML data looks like.
Here's a small snippet of JSON format:
And here's a snippet of XML format:
This is an example of how the same data can be passed off in these two different formats.
So long as the data is text-based, you can use these formats. If you want to pass image data or any other media information, you can pass the filenames or URLs to the media files within these formats.
How does your application process this data?
Now that the data has been set and passed by the webhook, how does your application know what to do with it?
This brings us back to our "assistants" example. For both the assistants, we initially mentioned what needs to be done with the information that they receive.
Similarly, we need to tell our application what to do with the data that comes in from the webhook. This is a one time task and once set up, it will work with no intervention.
The coding part of using the webhook data is out of scope for this article, let me give you an example of how the process will work in layman terms.
- The user performs an action that triggers the webhook
- The webhook collects the required data from the user action, and converts it into JSON or XML format
- The data is then passed off to the destination that we specify in the beginning while setting the webhook to interface up
- Our application receives the data
- Since JSON and XML formats are understood universally by programming languages, they can break down the data into single elements
- Once the data has been broken down element-wise, each element will be mapped against the existing value table, for example, columns in a database
- Finally, the mapped data is stored in these specific columns
What are the applications of a webhook?
The data is real-time, so there are many applications for webhooks. Your application server can use the data generated by these webhooks to keep a track of how many emails were delivered, opened, and clicked.
For example, Pepipost uses webhooks to pass email delivery related information as it occurs, in real-time (see the in the "what are webhooks" section).
The entire process of leveraging webhooks in any application of yours will be the same irrespective of the application:
- There's one app that listens for the incoming webhook payload and creates a JSON object with data from the event notification
- Webhook endpoint can be configured with the APIs to generate a webhook notification for your HTTP request
- A middle-layer that breaks down and maps the data according to the data set
- The final layer where the data is stored or sent for further processing
This article aimed at giving you a complete conceptual understanding of what webhooks are, and how you can use them for your applications.
If you have any more questions, feel free to let us know using the chat box on the bottom right.
Interested in check if emails from your domain are landing in Spam? Here is the right tool for you - Email Blacklist Tool