Webhooks
A webhook is an automatic HTTP request that one service sends to another's URL when an event happens, such as a successful payment, a new commit or a message to a bot. Instead of repeatedly asking an API whether something has changed, the receiving application is notified immediately. Webhooks are used by Stripe, GitHub, Telegram, Shopify and most other online services.
Key facts
| What it is | An HTTP callback: the provider calls your URL when an event occurs |
| Direction | From the service to your server (the reverse of a normal API call) |
| Format | Usually an HTTP POST with a JSON body |
| Security | HTTPS plus a signature, most often HMAC-SHA256 with a shared secret |
| Reliability | Providers retry failed deliveries; receivers must handle duplicates |
| Term | Coined by Jeff Lindsay in 2007 |
| Open specification | Standard Webhooks (standardwebhooks.com) |
What is a webhook?
A webhook is a way for a service to tell your application that something has happened, at the moment it happens. You register a URL on your server, for example https://example.com/webhooks/payments, and choose the events you care about. When such an event occurs, the service sends an HTTP POST request with the event details to that URL.
A normal API call works the other way round: your application asks the service for data. A webhook is sometimes called a "reverse API" because the service calls you.
How do webhooks work?
- You create an endpoint on your server that accepts POST requests.
- You register its URL with the provider and select events, such as
payment_intent.succeededin Stripe orpushin GitHub. - The provider gives you a signing secret.
- When an event happens, the provider sends a POST request with a JSON body and a signature header.
- Your server checks the signature, quickly answers with a 2xx status code and processes the event.
- If your server does not answer or returns an error, the provider retries the delivery later.
What is the difference between webhooks and polling?
| Webhooks | Polling the API | |
|---|---|---|
| Who starts the request | The service, when an event happens | Your application, on a timer |
| Delay | Seconds | Up to the polling interval |
| Load | A request only when something changes | Many empty requests |
| Requirements | A public HTTPS address that can receive requests | Only outgoing requests |
| Reliability | Depends on retries and your handling of failures | You control when to check again |
Many systems use both: webhooks for speed and occasional API checks to catch events that were missed.
Where are webhooks used?
- Payments — the Stripe API and payment gateways notify a store that a payment succeeded, failed or was refunded, so the order status is updated even if the customer closed the browser.
- Code and CI — GitHub sends events about pushes, pull requests and issues to build servers and chat bots.
- Messengers — the Telegram Bot API can deliver new messages to a bot through a webhook set with the
setWebhookmethod instead of the bot polling withgetUpdates. - E-commerce and CRM — Shopify and CRM systems report new orders, customers and status changes.
- Developer tools — issue trackers, databases and AI services report completed tasks and changes.
How do you receive a webhook securely?
Anyone can send a POST request to a public URL, so the receiver must check that the request really came from the provider. Most providers sign the raw request body with HMAC-SHA256 using the shared secret. This Node.js example with Express checks a GitHub webhook, whose signature arrives in the X-Hub-Signature-256 header:
import crypto from 'node:crypto';
import express from 'express';
const app = express();
const SECRET = process.env.WEBHOOK_SECRET;
async function handleEvent(deliveryId, event) {
// Save the delivery ID to skip duplicates, then do the real work
}
app.post('/webhooks/github', express.raw({ type: 'application/json' }), (req, res) => {
const received = Buffer.from(req.get('X-Hub-Signature-256') ?? '');
const expected = Buffer.from(
'sha256=' + crypto.createHmac('sha256', SECRET).update(req.body).digest('hex'),
);
if (received.length !== expected.length || !crypto.timingSafeEqual(received, expected)) {
return res.status(401).send('Invalid signature');
}
res.status(202).end(); // answer first, process afterwards
const event = JSON.parse(req.body.toString('utf8'));
handleEvent(req.get('X-GitHub-Delivery'), event).catch(console.error);
});
app.listen(3000);
The signature must be computed over the raw bytes of the body, before any JSON parsing, and compared with a constant-time function such as timingSafeEqual so that attackers cannot guess it by measuring response time.
Best practices for webhook receivers
- Answer quickly. GitHub expects a 2xx response within 10 seconds; put slow work into a queue and process it in the background.
- Make processing idempotent. Providers can deliver the same event more than once, so store the event or delivery ID and skip repeats.
- Do not rely on order. Events can arrive out of order; check timestamps or fetch the current state through the API.
- Expect retries. Stripe retries failed deliveries in live mode for up to three days with increasing intervals; GitHub does not retry automatically, but deliveries can be redelivered from the settings.
- Reject old requests. If the provider signs a timestamp, refuse requests that are too old to prevent replay attacks.
- Use HTTPS only and keep the signing secret out of the code.
The Telegram Bot API, for example, lets you pass a secret_token when calling setWebhook; Telegram then sends it in the X-Telegram-Bot-Api-Secret-Token header of every request.
How do you test webhooks locally?
A local computer usually has no public address, so developers use tunnels such as ngrok or Cloudflare Tunnel, or provider tools: the Stripe CLI command stripe listen --forward-to localhost:3000/webhooks forwards test events to a local server. Services such as webhook.site show incoming requests in the browser, which helps to inspect the format before writing code.
Sources
- Receive Stripe events in your webhook endpoint — Stripe (accessed 1 December 2026)
- Validating webhook deliveries — GitHub Docs (accessed 1 December 2026)
- Telegram Bot API — Telegram (accessed 1 December 2026)
- Standard Webhooks — Standard Webhooks (accessed 1 December 2026)
- Webhook — Wikipedia (accessed 1 December 2026)