TAKE A BREAK
Photo by Claudio Schwarz on Unsplash
So, what is a webhook? A webhook is a way for one app to send information to another app automatically, the moment something happens. Instead of your app repeatedly asking whether anything has changed, the sending app pushes the update to a web address you set up. That address is called an endpoint, and the message that arrives is usually a small JSON file describing what happened.
The term sounds more technical than the idea. In this explainer, we use one analogy from start to finish, walk through a real two-app example, and finish with a test you can run without writing any code.
Think about your front door. You could spend the afternoon standing at the window, checking the street every few minutes for a delivery. Or you could wait for the doorbell, which only rings when someone is actually there.
A webhook works like the doorbell:
Standing at the window every few minutes is what developers call polling. We will compare the two shortly.
Imagine a small online shop. Each time a customer places an order, the team wants a message in their chat channel so someone can start packing the box. Here is how a webhook handles it:
A simplified payload might look like this:
{
"event": "order.created",
"order_id": "1042",
"items": 2,
"total": "49.90",
"currency": "USD"
}
Nobody had to check for orders. The message arrived when the order happened, and payment and commerce platforms often work this way. Stripe, for example, sends webhook events to your app as a JSON payload that includes event information, delivered over HTTPS (Stripe's webhook documentation).
People often ask whether a webhook is an API. The two work together, but they play different roles. An API is a set of rules that lets one program request data or trigger actions in another. A webhook reverses the direction: the source sends data to you when something changes. If you want the request-and-response side in detail, our REST API explainer covers how those calls work.
Polling means your app checks the source on a schedule, usually with ordinary API calls like the ones described in our REST API explainer. Webhooks flip that pattern. GitHub's documentation says webhooks require less effort and fewer resources than polling an API. When a subscribed event occurs, GitHub sends an HTTP request with data about the event to the URL you specified (GitHub Docs: About webhooks).
| Polling | Webhook | |
|---|---|---|
| Who starts the request | Your app | The sending app |
| When it checks | On a schedule | When an event happens |
| Wasted requests | Many, if nothing changed | Few |
| Setup | Call the API and read the result | Needs a public endpoint |
| Best for | Periodic reports, sources without webhooks | Time-sensitive events like payments or new tickets |
Polling is not wrong. If you only need a daily summary, or the source offers no webhooks, a scheduled check is simpler to build. Webhooks shine when timing matters.
The response step matters more than beginners expect. GitHub's documentation explains that if the server takes too long to respond, GitHub ends the connection and treats the delivery as a failure (GitHub Docs: Handling webhook deliveries). The safe pattern is to accept the message quickly, return a success code, and do the heavier work afterward.
Failures are normal. Your server could be down for maintenance, a network connection could drop, or your code could crash on an unexpected payload. When that happens, the message may never reach your app, unless the provider tries again.
Three problems come up again and again:
Good webhook code plans for all three from day one, rather than treating them as edge cases.
A webhook endpoint is a public URL, so anyone who finds it can send it a request. Twilio's explainer describes an endpoint as a publicly reachable URL on your server that accepts incoming HTTP POST requests from a provider (Twilio's guide to webhooks). That openness is why many providers sign their messages. The sender uses a secret key to generate a signature from the payload. Your app recalculates the signature and compares the two. If they do not match, you reject the request.
The most common method is HMAC, a standard way to create signatures using a hash function. Keep the secret out of your code and your logs, and reject any request that fails the check. Check your provider's documentation for the exact steps. Stripe's webhook guide, for instance, explains how endpoints receive and verify events.
You can see a webhook in action in about five minutes:
Look for three things: the POST method, an event type field, and the data itself. You have just seen a webhook from start to finish. Use test repositories and dummy data, never real customer information.
No. A webhook is a notification that one app sends to a URL you control. A REST API is a set of rules for requesting data or actions. Many systems use both: the webhook tells you something happened, and an API call fetches the full details.
Not quite. The URL is the endpoint, the address that receives messages. The webhook is the whole arrangement: the subscription to an event, the HTTP POST, and the payload that follows.
Use polling when the source offers no webhooks, when you only need periodic checks, or when your system cannot receive incoming requests, for example because it has no public address.
A payment platform notifying your app when a customer pays is a common one. A code repository notifying a build system after a push is another. The online store example above follows the same pattern.
A webhook is a doorbell for software. The sending app rings your endpoint when something happens, and your app responds. It saves effort compared with constant checking, but it requires a reachable endpoint, a plan for failures, and signature checks. Start with a test URL, look at a real payload, and build from there.