Webhook
Last updated
Last updated
Use webhooks for event-driven systems. They allow your application to receive notifications or trigger actions when specific events occur, such as data updates or user actions.
Webhooks are a feature that helps developers update events in real time. Webhooks are also known as web callbacks and HTTP push API. The server will automatically notify and send data from an event on the website. For example, registration forms from customers, purchases, comments or sending support emails.
Webhooks are a very handy technology for implementing event responses on your website. Webhooks provide a solution to help server-side applications notify client-side applications when an event occurs on the server (event reaction). Therefore, the client-side application will not need to constantly ask or check with the server-side application.
Many people also often refer to Webhooks as “Reverse APIs”. Normally for APIs, the client-side application will call the server-side application. However, when there is a webhook, the server-side will call the webhook (end-point URL provided by the client-side application), for example, the server-side application calls the client-side application.
This is a very useful feature in implementing event reactions on the website. When a new event occurs on the server, Webhook will provide a mechanism to help the server-side application notify a client-side application.
The Discord webhook was created so that when setting up a Bash script it will help you check the status of a list of websites. From there, we will check for specific notifications from the server to your Discord channel.
Discord is one of the hosted chat systems similar to Slack. Everyone can install the messaging system for free through Discord. It allows you to communicate through: text, images, audio and video. It often offers premium features that help you sign up for free, and it will have dedicated client applications available for macOS, Linux, Windows, iOS.
Facebook Webhook is a convenient feature for managing personal pages on Facebook. Its features are mostly the same as Discord Webhooks.
So we have learned what Webhooks are and Webhooks on Discord as well as on Facebook. The article will give you some more specific examples in the following section. They will help you better understand what Webhooks are in practice.
Example 1
The AirVisual air pollution measurement application will send a notification to your phone about "The air pollution level in Ho Chi Minh City is very bad (AQI about 250 - 270). After receiving this notification from the server, the application will immediately display a notification on the phone to warn the user.
Example 2
MailChimp is an automated marketing tool developed based on Webhook. Basically, how it works is as follows. First, MailChimp will receive data files about customers who have signed up for web notifications or customers who have made purchases on the web. Then, when an event occurs, MailChimp will send email notifications to these customers, of course divided by case. For example, loyalty programs are only sent to customers who have accumulated enough purchases. The new customer program will be sent to potential accounts. In addition, MailChimp also manages responses about subscribing and unsubscribing to target target groups.
MailChimp – a professional email marketing tool today. Webhooks are used by MailChimp for important events such as signing up for newsletters or unsubscribing and changing user information.
Those who register for an account on the website will be connected to MailChimp. This helps you manage data and send daily emails quite easily.
Example 3
Online payment portal Stripe also allows the use of Webhooks with many different types of events. For example, did the payment go through or not, is the date correct? This makes re-doing the operation more accurate and easier.
Webhook also supports payment gateways like Stripe to optimize customer experience. The webhook will let the system and customers know whether the payment was successful or not, what the payment time is, the payer's proof of information... These data will help make payments more accurate. more precise.
The basic function of Webhooks is that they can be integrated into Website services without the need to add new infrastructure. Because it uses HTTP, it can do that.
Webhooks are user-defined callbacks that are typically triggered by some event. It's like pushing code to a repository or posting comments to a blog.
Simply understanding the function of a Webhook is that it can be integrated into website services without needing to add new infrastructure thanks to HTTP. A common use is to enable builds with continuous integration systems.
Webhooks are often used by programmers to update events in real time in the most resource-efficient way possible. That's why Webhooks are used in this case. In addition, Webhooks can also be used via API when your API is not very good or even doesn't have an API to start with. So through Webhooks, you can create a solution that provides the data your application needs to operate smoothly right away.
There is a small note like this, although Webhook is quite flexible, if it is not used frequently to call data (because it only works when there is new data or events on the system), it leads to the possibility that It is not possible to get the latest updates if the system stops working for some unexpected reason.
The first step to using Webhooks is to prepare a URL for your website. Your website or application needs to be public so everyone can access it. Once you have the URL, send it to the Webhook. The Webhook provider will be responsible for sending the request back to the user.
Typically, there are two main ways Webhooks respond to data for the user's URL. It's like JSON and XML. Before this process begins, users will receive information about these APIs. You can even redesign the API according to your own needs.
Debugging is a necessary step for Webhooks to operate smoothly and be suitable for each different project and program. Debugging a Webhook sometimes makes us feel uncomfortable because the process is very complicated and time-consuming. You need to activate each part and then monitor their reactions. From there, make a diagnosis of the error and plan to fix it. However, fortunately, there are currently many tools that support Debugging a Webhook that have been invented. You can consider using some of the following tips to make fixing Webhook errors no longer difficult.
If you find observing and diagnosing Webhook errors too difficult, use RequestBin. This tool will be responsible for observing and collecting the responses that Webhooks give. Your job is to receive the error response list that RequestBin provides back.
If you don't know how to create a suitable request for a Webhook response, use some smart tools like cURL or Postman. They are capable of generating simulation requirements with high accuracy.
In addition, users can also publish code on the local machine using the ngrok tool or monitor the operation process using Runscope.
What is Securing a Webhook? This is a security process to prevent unauthorized intrusions. This is because the URL you provide to the Webhook is public. That's why bad guys can follow that public information to send you fake feedback. Users need to increase the security of Webhooks to prevent those unnecessary risks.
To secure Webhooks, the most commonly used method is to add a token to the URL. With this option, your URL will act as a unique identifier. Bad guys will not have the opportunity to steal and duplicate information.
The above method can prevent most attacks. But what if the hacker chooses to fake the notification and response? You can add a signature along with the data. All data exchange activities should have an accompanying signature to determine fidelity. Thus, bad guys will not have the opportunity to fake requests.
There are 2 popular types of Webhook structures today. The first type of Webhook will not care about anything after its task of sending data to the client is completed. If there is an error on the website, the data sent to the customer will completely disappear. And if the server side is not notified, it will not know that those errors have just occurred.
The second type of Webhook is more careful. The Webhook system will store a copy before sending data to the customer. Then, when there is a response from the client, the Webhook confirms that the task was successful. Otherwise, it will resend or notify the server about the failure of the request. You should determine in advance what type of Webhook you use to have an appropriate solution when encountering errors.