From system failure events to trade and stock notifications, modern software simply cannot wait for a poling process or a nightly refresh. Webhooks are one way to integrate systems by a series of near-instant message updates, each tied to an independent event.
In this article, we'll examine what webhooks are -- including how they differ from APIs -- and what their use in the real world looks like.
What are webhooks?
Webhook is a term used to describe a callback method in which one software system uses APIs to instantly notify another of an event. That means one application can send a web-based message request every time a qualifying event happens. To use webhooks effectively, the notifying system must possess the ability to register events and link them to a URL. When a particular event happens, like a buy order on a trading desk, the URL is called over the web with a payload of the event.
An API (in the form of the new URL) will then notify a second system. This flips the idea of the API around: The platform isn't asking for anything, but instead relays its own request message. Exactly what message this contains, as well as where it goes, is completely customizable, requiring only a user-supplied recipient web address.
The term webhook generally means posting an event to another system over the web through an API. Webhooks use HTTP POST messages to trigger actions in another application when an event fires. The current standard data format for this is JSON, but it's possible to build a webhook system using SMS or SMTP events. Developers can create command lines, set up configuration files or pipe it directly through a user interface to achieve this.
A webhook needs two things: a sender with tools to recognize an event and do something, and a receiver -- an application with an API to send the messages to. Webhooks are an easy way to send text-based responses to users when certain events occur inside the application. Most modern platforms support webhooks, or at least a similar architectural approach, such as Gmail, Slack, Discord, GitHub and Google Calendar.
Some real-world examples of webhooks include the following:
- Instagram photos that automatically upload to Twitter accounts.
- A connected doorbell configured to flash certain lights inside a home as it rings.
- Sending GitHub update notifications to Slack or Discord channels as messages.
- Creating a Microsoft Teams channel that relays messages when people buy or sell certain stocks.
APIs respond to requests; webhooks are a messaging strategy that is event-based. Thus, the webhook will call the downstream system's API when something happens. For instance, let's say a developer runs a Discord channel related to a GitHub project and wants to have an automated message alert the channel to any new code updates that occur in the public repository. By adding a webhook via Discord's channel integration options, GitHub will not only send an automated message to the channel based on certain predetermined events, but also configure it as a link to a page that shows the details of the change.