How to Test Webhooks using ngrok

Webhooks are an inter-application notification mechanism. For example, GitHub can notify an application via an HTTP request after each commit on a repository. The notified application can thus perform an operation immediately after the commit. Here is the GitHub screen for adding a webhook:

The problem of webhooks is that the external service (here GitHub) can only make a request on an URL accessible via the internet (public address). During development, the developer’s post rarely has a public address. In this configuration, it is therefore difficult to test the integration with the external application. This is where ngrok comes in 🙂

Ngrok creates a tunnel between the development workstation and the ngrok servers. Once the tunnel is created, we obtain a public URL of the type “sample. ngrok. com “which ultimately points to our machine. We can use this URL to test the integration with an external service.

Source: https://ngrok.com

How to use ngrok?

First, you have to create a free account on their site. This provides the authentication token needed to use the application

We record the token obtained on our post:

ngrok.exe authtoken <token>

Then we must launch the tool specifying the protocol to use (HTTP in our case) and the port of the application on our machine:

ngrok.exe http 4242

If all goes well you should see something like this:

You can now open the inspection interface at http://localhost:4040 . This console displays all HTTP requests and also allows you to replay them as needed (convenient for the dev).

That’s it, it remains only to use the public URL provided by ngrok (here http://859ca31a.ngrok.io ) to access the site.

Note: IIS Express does not accept requests from a remote machine by default. This is the workaround, but it is probably easier to use IIS directly.

For more advanced needs, there is a paid version of ngrok. It allows for example to reserve a subdomain, but for simple tests the free version is sufficient.

Conclusion

Ngrok allows you to expose your machine on the internet in 2 minutes. This is very useful for testing webhooks, but it also has other uses. For example, you can test a mobile application that uses web services hosted on your dev machine.

With a little imagination, you will probably find other use cases. That is How to Test Webhooks using ngrok, simple enough.

 

You may also like...

Leave a Reply

Your email address will not be published.