Testing Webhooks Was a Pain – So I Fixed the Glitch

Popularized by GitHub, Webhooks are the modern way for apps to receive notifications / events from other servers. But testing Webhooks has always been pretty painful, especially if you want to automate those tests. So I created a little app to make it easier. Before we get into that lets cover the basics…

A Webhook is a way for you to define a URL that is called by another service when a particular event occurs. For example, you can configure your repo on GitHub to have a Webhook that calls http://foo.com/pr when a new Pull Request is created. The old alternative to this is polling (bad).

Testing Webhooks is painful because the service calling your Webhook can’t reach your localhost and it can be hard to get the payload of the request. So I created a very simple app to help with this. To use it set the Webhook URL to:

https://echo-webhook.herokuapp.com/SOMETHING_UNIQUE

Now when the other service does its POST to that URL the request body is cached and can be retrieved via a GET to the same URL. Here is a simple curl test:

curl -H "content-type: application/json" -d '{"foo": "bar"}' https://echo-webhook.herokuapp.com/foobar
curl https://echo-webhook.herokuapp.com/foobar
{"foo":"bar"}

Your app can get the payload of the Webhook request and if needed pass it to your localhost Webhook for testing. All of the code for this app is on GitHub: https://github.com/jamesward/echo-webhook (Note: If you don’t want your data going through my app just git push that repo to your own Heroku app.)

I hope this is useful for others! Let me know if you have any questions or problems.