The average consumer will use a website or app without giving much thought into how it works. They browse, purchase, subscribe, and contact a business through the online front. However, a business owner does not have the privilege of things just working. The website owner needs to ensure that the app or website does what it needs, as it is often one of the main places a customer interacts with a company. One tool that makes websites function as a consumer expects comes in the form of webhooks.
What Is A Webhook?
Websites require APIs to perform certain functions, such as processing an order or collecting a consumer’s information for contacting in the future. One recently emerging API concept comes in the form of webhooks. A typical API or Application Programming Interface collects an information request inputted by the consumer, related to the type of API employed. The API then processes that API request and returns the results to the consumer. Webhooks work similarly, though with some differences, which have led to them becoming very popular.
Webhooks, also known as a web callback, reverse APIs, or an HTTP push API, provide applications with information, in real-time. A business that uses webhooks with its website or app will receive the new data from the site, as it happens. In comparison, an API without a webhook first needs to receive a request from the site owner, before it’s able to forward the information. A webhook will tell a user that the action has taken place without any prompting, while an API will need a user to ask if anything has happened before it tells them whether it has or not.
The process of a webhook is much more efficient for both the service provider and the consumer, as it effectively eliminates a step in the process. However, though APIs are somewhat simple to implement, with basic coding knowledge, the benefits of webhooks are not so easily obtainable.
Setting Up A Webhook
Setting up of a webhook differs between the various webhook providers out there, meaning the below is only a rough idea of what to expect when the time comes to employ this service. A webhook gets set up as follows:
- A business then gives that newly created URL to the webhook provider.
- With the webhook now implemented to the website or app, it will activate whenever a particular action occurs. Some of those possible actions are detailed below.
- The webhook service then creates a POST request to the URL connected to the service. This incoming webhook POST lets the URL owner know that the specified action has taken place.
- The server housing the URL receives that POST and then sends a reply to the webhook provider to let them know that the webhook process was completed or not.
A Webhook In Action
Webhooks are a great way to automate a website and bring more convenience than their standard API predecessors. Though that is the case, it can be challenging to understand the advantages, without exploring a real-world application. One such place that many people have encountered a web callback, whether they know it or not, is on an e-commerce store.
A customer visits the store, adds an item to their shopping basket, and then checks out. The purchasing of an item is a particular activity that requires a webhook to work as intended. The action has taken place on the site and the webhook needs to tell the owner of the store.
As stated, the first step is for a webhook service to get set up, implemented with the site, and then connected with the webhook URL, also known as the payload URL, which is where the website owner receives the information. The e-commerce store processes the order and then translates the payload data into the webhook service format. With the data in a readable form, the e-commerce website or app sends an HTTP GET request. An HTTP GET request comes in the form of a standard URL, with additional text added to the end to let the endpoint, usually a website, know the request’s nature.
The webhook implemented into the site then takes the necessary action related to the request. In this case, the webhook allows the website or app to confirm the order and send an invoice without user interaction.
Without the use of a web callback, the website would send out a notification of the purchase, which the owner would have to act upon. The order would not get processed and the invoice would need manually typing out, which could be time spent elsewhere. Instead, the callback URL picks up the request and handles the rest, with minimal action required from the owner of the website or app.
In truth, the above is just one example, though webhooks can get used for nearly any action that requires two applications to work in tandem.
Other Uses Of Webhooks
The above e-commerce is just one example of webhooks in action. As stated above, if two applications need to work together to complete an action, then a webhook can be used. Some examples include:
● Managing a subscriber list – A website that provides newsletters can make use of webhooks to manage the whole process. A user can subscribe, unsubscribe, and update their profile. If the website had an API, the website owner would have to ask the system to check if there have been any changes, whereas a webhook will automatically pass on that information.
● Processing of payments – A webhook can connect with a purchasing gateway to complete a transaction automatically. The service can then send a webhook notification, once payment has gone through the connected system. The system can also send a warning if the payment was attempted, but bounced.
● Managing customer data – Many companies use CRM systems to manage their day-to-day business. A webhook working in conjunction with such a service will update user details, as a user updates them. Such an application can apply to a subscriber list as well. However, one such use might be an energy company, or insurance company, that charges to an address, so needs records that remain accurate, so the form data, with the use of a webhook, can go straight to the necessary records without further user input.
● Forwarding data to cloud software – Cloud software has given businesses a solution to the difficulty of implementing and maintaining on-site data storage. With the use of a webhook, cloud software becomes even more convenient. Data can instantly get uploaded to the cloud service without any input.
A webhook, no matter its purpose, delivers the requested data to a URL that anyone can access, provided they know the address. However, because that URL is handling customer information, from contact info to financial details, a company should take extra steps to protect that information. The first line of defense comes in the form of HTTPS and TLS.
HTTPS and TLS
The primary form of security for a webhook application comes in the form of HTTPS. HTTPS secures the connection between the user’s browser and the server of the website. The owner of the server should download a TLS security certificate. This certificate encodes the data getting passed to the server. Though implementing HTTPS won’t stop people accessing the public URL, it will protect the information getting transferred to the website server.
With HTTPS and a TLS security certificate, the data that gets handled is secure. However, the URL of the app for processing that data is not. Basic HTTP authentification can do just that. In short, implementing basic authentification will ensure a user visiting the protected URL, will need to input a username and password to authenticate their ID. However, as the name suggests, the authentication is basic, so it should get used in combination with other security schemes.
Implement Webhook Signatures
Webhook signatures confirm where the request has come from. The webhook service user can check each delivery of the webhook data to make sure the signature matches the web service which has sent it. Unfortunately, not all webhook providers have this action as part of their service.
Debugging A Webhook
As with any piece of computer software, things don’t always go as planned. Webhooks are no exception, though come with the additional issue of having to wait for the webhook to get activated before being able even to understand there is an issue. Luckily, despite that being the case, it can be relatively easy to decipher an issue with the webhook. Some ways to debug a webhook system include:
Using The Webhook Service’s Debugger
The most popular webhook services come with a debugger built in. That debugger will flag any issues with the system, with those issues typically coming in two forms, a warning and an error. A warning notification comes if there was an issue with the webhook, but the request was still able to get processed. An error means that the webhook request was not able to be processed at all. These two specific events will come with a variety of information, including:
● What the warning or error issue was
● Some possible reasons as to why the error occurred
● Some possible solutions for the issue
● The HTTP request that led to the issue in question
Testing The Webhook In The Browser
A webhook URL is just another web application, meaning it can get tested directly from the browser. Test the webhook services, visit each URL for the webhook receiving application, and then check that everything is working as intended. Some web browsers will allow a user to check which, if any, XML files are returning errors.
Depending on the webhook service used, the service might issue HTTP redirects. A user of a webhook should double-check that these redirects go to the intended endpoint. A user can use a third-party application to ensure everything is working correctly, and if not, they will know where the problem stems.
Testing A Webhook
As stated above, one way to get to the root of any webhook issue is to test it. However, a responsible user should test a webhook before deployment to avoid things going wrong when they are needed most. Before any testing can take place, the webhook must get implemented to the web or app server.
With the infrastructure in place, the tester can request the action the webhook provides. The activity should take place and then return a successful signal. With the operation completed, a callback should get delivered to the webhook URL.
With the action hopefully completed, the tester needs to review the data shown in the workflow to ensure everything did work. How long did it take for the task to complete? Was the action completed as intended? What was the delay between the completion of the webhook payload and the delivery of the success signal?
Load Testing Webhooks
The above is a guide for how a single user would test a webhook, though in a real-world application, depending on the popularity of the app or site, more than one person will be using it. Before the launch of a new webhook, a tester should ensure it will work with both a single user and hundreds of users, all at once. A tester has to perform the same test above but with multiple users and multiple webhooks if necessary, meaning there are more HTTP callback responses to analyze. The best way to do this is with a load test framework, that should already get included in the webhook service. If not, a tester has to write the test service themselves.
Webhook vs. API
As stated above, a Webhook and API are very similar. Up until this point, a webhook may seem like the end-all solution, though an API does have some advantages to it. The main difference is that an API requires user input to do what it needs, whether that is to forward a notification through a push notification API, perform a transaction through a transactional API, or manage SMS communication with an SMS API. On the other hand, a webhook is automated. The webhook gets set up and then tied to a specific webhook trigger event. A consumer can use a sign-up form for email marketing and then will automatically receive an email to confirm their subscription, with the email getting sent by the webhook application.
When To Use A Webhook
Webhooks tend to be best suited for smaller requests, which are less taxing on a system. The most common use of a webhook is to provide real-time updates, which will be necessary if the purpose of the app is to provide such updates. Alternatively, a webhook may be suitable if no API does what a user needs. With some tinkering, a webhook can fulfill most functions.
However, the fact that webhooks can provide real-time updates is also a downside to the service. Webhooks forward data as it is given, as opposed to an API that requires a request to be filed. If the system that provides the webhook goes offline, any updates made to the site or app may never get to the website server.
When To Use An API
APIs get best used when the data it is handling is updated regularly. That’s because an API needs to receive a POLL to hand over data, with each POLL requiring resources, which would get wasted if there was no data to retrieve. A website server can get set to request these polls automatically at intervals that best suit the website admin.
There are various APIs available, doing several different things from powering map apps to providing messaging apps.
Webhooks And APIs Work Best, When Working Together
To pit both webhooks and APIs against each other is foolish, as there is no reason why they can’t work together. An API allows information to get relayed between two parties, giving a consumer a chance to interact with a business. However, the webhook lets someone put in a single request, to then subscribe to a business, without further input, only to receive an event notification when necessary.
The Technical Terms That Come With Webhooks
On the surface, webhooks can seem complicated, especially with some of the technical terms that come with it. However, once a potential user has a basic understanding of these terms, webhooks become a bit simpler. With that said, these are the terms that often require some clarification.
The webhook service, is as the name implies, the service that provides the webhook. There are many of these webhook services available, including those from Google, Facebook, Twilio, and more. Some services are more specialized than others, so a potential user should do their due diligence to ensure the service meets their needs. These services then connect via the webhooks tab found in nearly all server settings pages.
The endpoint is a term used to distinguish the final destination of a request. Typically, a webhook endpoint refers to the server of a website employing webhooks.
HTTP or Hypertext Transfer Protocol is how a web client and a web server communicate with each other. It is a commonly accepted language that makes the internet what it is today. Every web server speaks HTTP and every web browser speaks HTTP. Without HTTP, a browser must learn a new protocol every time it connects to a server and with millions, if not billions, of web users every minute, that is impractical. Since HTTP is how data gets transferred, a webhook also uses this protocol.
So, HTTP is how services on the web communicate, leaving an HTTP request to be fairly self-explanatory. When a browser connects to a web server, it makes an HTTP request. The actual request will depend on the type of data that a user is looking to access, though it will always come in the form of HTTP. Two types of requests related to webhooks, though not exclusively, are GET and POST requests.
GET And POST Request
GET requests and POST requests are just two examples of HTTP requests. An HTTP GET request gets used to collect data from a web server. In comparison, an HTTP POST request gets used to send data to the web server, which would be the case with an outgoing webhook.
HTTPS is effectively the same as HTTP, though the additional S indicates that the communication is secure. Usually, HTTPS gets secured through the use of a TLS certificate and the web browser in use often indicates if the visited website has this encryption in place. HTTPS should always get used to secure consumer data, with webhook integration being no exception.
Similar Article: Programmable Voice-Changing How Businesses Communicate