Skip to main content

Web and APIs

What is a Webhook?

Definition

A webhook is an HTTP request a service sends to a URL you register whenever an event happens, so you are notified instead of having to poll for changes.

Also known as: HTTP callback, reverse API

Webhook in more detail

With an ordinary API your code asks a question and waits for the answer. A webhook inverts that: you give a provider a URL, the provider POSTs to it the moment something occurs — a payment succeeded, a build finished, an issue was closed — and your server handles the payload. It is the difference between checking your postbox every minute and having the post delivered.

Because your endpoint is a public URL that anyone can hit, the security work is not optional. Reputable providers sign each request, usually with an HMAC of the raw body plus a timestamp, in a header such as Stripe-Signature or X-Hub-Signature-256. You recompute that signature with your shared secret over the exact bytes received — parse-then-reserialise breaks it — and reject anything that does not match or whose timestamp is old enough to be a replay.

The other half of webhook engineering is delivery. Networks fail, so providers retry, which means the same event will eventually arrive twice; handlers therefore have to be idempotent, typically by recording the event id and ignoring ids already seen. Events can also arrive out of order, so treat the payload as a hint and refetch the authoritative object if ordering matters. Reply 2xx quickly and do the slow work on a queue: most providers treat a slow response as a failure and retry.

Webhook example

POST /hooks/payments HTTP/1.1
Host: yourapp.example.com
Stripe-Signature: t=1710000000,v1=5257a869e7...
Content-Type: application/json

{
  "id": "evt_1P9x2c",
  "type": "payment_intent.succeeded",
  "created": 1710000000,
  "data": { "object": { "id": "pi_3P9x", "amount": 4900 } }
}

# Your handler: verify the signature over the raw body,
# check whether evt_1P9x2c was already processed, enqueue
# the work, then return 200 immediately.

Webhook — common questions

What is the difference between a webhook and an API?
Direction. With an API your application makes the call; with a webhook the provider calls your application. A webhook is delivered over HTTP just like an API request, so the mechanics are the same — only the initiator differs.
How do I test a webhook on localhost?
Use the provider's CLI or dashboard replay feature, or a tunnelling tool that gives your local server a temporary public URL. Both let you receive real signed payloads without deploying, which matters because signature verification is the part most likely to be wrong.
What happens if my webhook endpoint is down?
Most providers retry with exponential backoff for hours or days and then give up, often disabling the endpoint after sustained failures. Because retries duplicate events, handlers must be idempotent, and you should have a way to re-sync from the provider's API after an outage.

Keep reading

Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.

Browse the A-Z glossary