Test a webhook locally, without ngrok

A webhook provider calls a public URL: it can't reach localhost. To develop locally you either open a tunnel to your machine, use the provider's own tool, or capture the request online and replay it locally. Each option has its use.

Option 1: a tunnel

A tunnel (ngrok, cloudflared, localtunnel…) publishes a public URL that forwards requests to a port on your machine. It's the closest to production: the provider calls your code live, on every event.

Trade-offs: a binary to install, often an account, a URL that changes on every run on free plans (to reconfigure at the provider), and a port of your machine exposed to the Internet while the tunnel runs.

Option 2: the provider's CLI

Some providers ship a dedicated tool. The Stripe CLI, for example, listens to your account's events and forwards them to localhost with a valid signature. It's the best choice when it exists, but it only covers one provider at a time.

Tunnel and CLI
# Tunnel: exposes localhost:3000 on a temporary public URL
cloudflared tunnel --url http://localhost:3000

# Stripe only: forwards the events of your account to localhost
stripe listen --forward-to localhost:3000/webhooks/stripe

Option 3: capture, then replay locally

Nothing to install: set a Tracehook capture URL as the endpoint, trigger the event, then replay the captured request against localhost with curl. You work on the provider's exact request (headers and body), as many times as needed, without exposing your machine.

The limit is clear: it's not real-time forwarding. Every new event has to be replayed by hand, and a timestamped signature (Stripe) becomes invalid after a few minutes.

Local replay
# 1. Body copied from Tracehook into body.json
# 2. Replay it against the local server
curl -i -X POST 'http://localhost:3000/webhooks/shop' \
  -H 'Content-Type: application/json' \
  --data-binary @body.json

Which one to choose

  • Discovering an event's format, writing the parser, reproducing a bug on a specific request: capture then replay.
  • Testing a live sequence of events (a payment followed by its confirmation): tunnel or provider CLI.
  • Checking the signature end to end: the provider's CLI, which signs every delivery with a fresh timestamp.
  • A locked-down workstation with no install rights: capture then replay, which only needs a browser and curl.

In every case

Don't leave a test URL configured in production at the provider: real events would go to a stopped tunnel or a capture URL. Use a separate endpoint, in test mode when the provider offers one.

Capture your first event, with nothing to install.

No sign-up