Public Beta: Direct engineering support available. Join Discord →
Guides
How do I stop writing webhook boilerplate?

How do I stop writing webhook boilerplate?

Keep the handler and hand the plumbing to a gateway. Every webhook project grows the same parts: a signature check, somewhere to keep raw payloads, a retry loop, and a way to re-run events after a bug. A gateway in front of your code does those once, so what you write per project is one function that does the work and returns a 2xx when it succeeded and anything else when it did not.

The one piece you still write

// The handler you keep once a gateway owns ingestion.
// handle(event) does your work; if it throws, the handler answers 500.
// Express: app.post('/webhooks', express.json(), webhookHandler(handle))
// In production, verify the gateway's signature header before this runs.
export function webhookHandler (handle) {
  return async (req, res) => {
    try {
      await handle(req.body)
      res.status(200).end()
    } catch (err) {
      console.error('webhook handler failed', err)
      res.status(500).end()
    }
  }
}

What you stop writing

  • The signature check. The gateway can check the sender's signature before anything else runs, and reject the request if it fails.
  • The raw-payload table. Each event is stored as it arrived, headers included, for your plan's retention window (Pricing).
  • The retry loop. Your handler only has to tell success from failure. See How do I resend failed webhooks?
  • The re-run script. After you fix a bug, you replay the events still inside that window through your current code instead of asking the vendor to send them again.

Why the second project is the one to stop on

The first time, the plumbing feels like the project. The second time you recognise it: the same retry table, the same "did that event ever arrive?", the same afternoon spent re-running history after a bad deploy. None of it is the thing you were asked to build, and none of it is visible to the person waiting for that thing.

This covers sources that send webhooks. If a vendor only offers a list API, you still page through it yourself. How do I paginate through a webhook backfill? and How do I resume a webhook sync from a cursor? have those loops.

Webhook ingestion without building a pipeline

  1. Point the vendor at the gateway's ingestion URL instead of your endpoint.
  2. Add your endpoint as a destination.
  3. Deploy the handler above.

Need somewhere for the next project's webhooks to land? Slashbin's Free plan takes an account, not a card.

Start Free

(opens in a new tab)

Related