Skip to content
Blog

Testing webhooks locally: you only need one delivery

Getting a webhook to reach your laptop is the part everyone writes about. Point a tunnel at your dev server, paste the public URL into Stripe or GitHub, done. That takes a minute, and Webhooks on localhost covers it, signature headers and all.

The part that eats an afternoon is the loop after it.

You trigger a test event. Your handler throws on line three, because the payload nests one level deeper than you assumed. You fix it, restart, and now you need that event again, so you go back to the provider's dashboard and click resend. Then you need it again. And again. Every iteration is a round trip through someone else's system, and those systems are not built for your inner loop: some rate-limit you, some want a fresh test payment, and some only fire on a real push you cannot fake.

That loop is backwards. You do not need the provider to keep delivering. You need one delivery, and then the ability to run it against your handler as often as you like.

Capture once, replay locally

Every zgrok tunnel starts a request inspector on your own machine by default, and prints its address in the banner:

Inspect: http://127.0.0.1:4040

Open it, click the delivery, and you get the request as it arrived: every header, the body, the status your handler returned. Then press Replay.

Replay sends the captured bytes to 127.0.0.1:<your port>, straight to your app. It does not go back out through the tunnel. The provider never learns that you re-ran anything, so nothing fires again on their side and no counter moves there. Your own handler does run again in full, side effects and all. That is the point, but it is worth saying out loud before you replay a payment event forty times.

So the loop becomes: trigger the event once, then edit, replay, read, repeat.

Why this beats a saved curl command

The obvious alternative is to copy the payload into a file and curl it at your app. That works right up to the moment you touch signature verification, which is the one part of a webhook handler most worth getting right.

A hand-written request carries a signature you made up. Sending it proves your verifier rejects garbage, which was never in doubt. Replay sends the provider's real headers back byte for byte, so Stripe-Signature or X-Hub-Signature-256 is the genuine one computed over the genuine body, and the path that runs in production is the path you are testing.

One thing to know before you blame your code: a verifier that also checks the delivery's timestamp will start rejecting a replay once that delivery is old enough. That is the verifier doing its job. Grab a fresh delivery and carry on.

What it will not do

The inspector is deliberately small, and the limits are worth knowing before you rely on it:

  • It is a window, not storage: 50 requests, held in memory, discarded the moment the tunnel stops.
  • Bodies are captured up to 128 KB per direction. A request truncated at that limit is refused for replay, and tells you why, rather than being replayed as a body that contradicts its own Content-Length.
  • A protocol upgrade, the 101 that starts a WebSocket, is not a request and response pair, so it cannot be replayed either.
  • The inspector binds to loopback only and answers only to a loopback Host. Captured bodies hold whatever the provider sent you, signatures and all, so that port never leaves your machine.

One more thing replay buys you

A webhook endpoint is a URL you registered somewhere else, so a tunnel address that changes between sessions is a genuine cost, and on Free the assigned address does change. Replay takes most of the sting out of it: once you hold the delivery, the URL no longer has to be current for you to keep working.

If you would rather register the endpoint once and forget it, Webhook Debugging covers the claimed subdomain that survives restarts on Pro.

Try it

bash
zgrok http 3000

Register the printed URL with your provider, trigger the event once, then open the inspector address from the banner and stop asking anyone to resend.

The full reference is in Webhook Debugging and Request Inspector.

Back to blog