Typically, developers want to implement, debug and test the receiver locally in a development environment. If we want to test it locally, we can only test it with the artificial events produced by the mock server. What to do when we want to test the receiver against some real events from the API provider? To be able to receive real events from the API provider, the receiver needs to be accessible from the public internet. The developer machine, however, should not be accessible from the internet.

Ngrok (https://ngrok.com) is a tool that exposes local servers behind NATs and firewalls to the public internet via a secure tunnel. Ngrok consists of two components: A cloud component and a local component that needs to be installed on the local machine. Between the two components, Ngrok establishes a secure tunnel. The Ngrok cloud component provides a publicly accessible URL. Whatever is sent to that public URL is tunneled to the local installation of Ngrok and made available to the local development server. This setup allows us to make our event receiver endpoint available on the internet and accessible for the event sender, even though it is running on a local development machine.

To set this system up, we need to create an event subscription with the Ngrok URL as the receiver. Now the events arrive from the API provider on our local receiver, where we can test and debug the receiver based on real event data.

Even though this setup is working for development, we need to deploy the receiver for production.

LearnΒ more about Events in RESTful ArchitecturesΒ in the Webhooks Book.

How to Test your Webhook (a.k.a. Event Receiver)
Tagged on: