what is a webhook

What is a Webhook?

You may have seen webhooks mentioned in some of your apps before and thought: “Would I benefit from using a webhook?” In a word: yes.

In simple terms, webhooks are an easy way for one app to “speak” to another, allowing data to be passed between systems that are otherwise unconnected. Applications and services such as Twitter, Discord, Youtube, and Github all use webhooks to provide you with the services you know and love.

So that begs the question: how do I use webhooks? Before we dive into that, let’s look at how webhooks work.

How does a webhook work?

To understand webhooks, let’s first look at an API. An API, or Application Programming Interface, is a set of protocols used for integrating application software. Communication between APIs uses HTTP requests to either retrieve data from a server or to send data to a client. Typically, data is sent in either XML or JSON format due to their ease of use. Learn more about API Monitoring.

When an API is used to communicate between a client and a server, there is no way for the client to inherently know whether the status of the server has changed. Because of this, the client must periodically sample, or request, the data from the server to check for any changes to its status. This happens on a loop until the desired event has occurred. At a basic level, the client sends HTTP requests to the server, waits for a response, then repeats this process until it’s told not to. Imagine Dave from work asks you for a report and every 5 minutes after that, Dave asks you whether you’ve finished that report until it’s finally complete. Annoying, right?

A webhook, on the other hand, takes Dave out of the equation. By removing the loop of constant HTTP requests, the server can let the client know when its status has changed. With a webhook, instead of the client consistently requesting data from the server, the server instead waits for an event to occur, or “fire.” This event triggers the webhook to send over an HTTP request to the client providing it with the new data. This simplifies the process of keeping track of a server’s behavior.

How can you make use of a webhook?

A webhook can be used in a number of different scenarios. For example, a common use for a webhook is invoicing purchases through an ecommerce website.

Say you have a customer who navigates to your website, selects an item, and checks out. Great! The customer purchasing your item would be an event to listen for. So then, how do we make the invoice?

First, you would need an invoice application that creates an invoice template. This serves as the template used for any invoice for an item purchased on your website. Then, you can take the webhook URL for that invoice template and set it in your ecommerce website’s app. That URL may look something like this:

https://mystore.com/invoices/purchases?Customer=john&item=tractor&price=500

Notice in this example URL that there’s some interesting data appended (added to the end). This is called “form-encoded” data, which is formatted in a way that can be sent right in the URL of an endpoint. In doing this, we can send the customer data immediately with the URL using an HTTP GET request. This is the simplest way to provide the data.

An alternative method would be using an HTTP POST request in which data is sent in either XML or JSON format. Here is an example of the same information represented in JSON:

{
"customer": "john",
"item": "tractor",
"price": 500
}

Once your invoice app receives this data via the webhook URL, the data can be added to the correct fields and an invoice can be generated.

Using Webhooks with Uptime.com

Uptime.com offers custom check types, including Custom Webhook and Heartbeat checks. These offer another helpful example of using webhooks in real-life scenarios.

Let’s say you have a server that contains sensitive data, and as such, is not open to the public. In case of a system failure or an otherwise fatal error, the appropriate team members will need to be notified at a moment’s notice to ensure that there is no disruption of services or corruption of the data stored on this server. A monitoring solution can cover your bases, but this can be difficult as the server is not open to public connections.

Uptime.com’s Custom Webhook check offers a potential solution as it does not request data from your server. Instead the Custom Webhook check waits for your server to send data via the unique webhook URL within a set interval. If your server misses this interval for any reason, the contacts configured for this check will be notified immediately through your chosen alerting methods and the investigation can begin immediately for minimal disruption.

Webhooks are a powerful function that we use every day across multiple applications, and for many purposes. Given their flexibility and simplicity, it’s no surprise that there are a variety of use cases within the Uptime.com platform that can utilize webhooks to achieve monitoring solutions tailored to your organization.

To view additional information about the nuts and bolts of implementing webhooks within your Uptime.com solution, please see our related documentation located here

Minute-by-minute Uptime checks.
Start your 14-day free trial with no credit card required at Uptime.com.

Get Started

Catch up on the rest of your uptime monitoring news