DEV Community

Ibrar Hussain
Ibrar Hussain

Posted on

How to test Webhooks on your localhost

There comes a time when you need to work with third party apps such as: Stripe, Paypal, Hubspot, and etc, that can send you webhook calls to your application. In order to receive those webhook calls you need to provide your application URL and set it up in their webhook section.

If you are developing your application on localhost then most probably your URL might look like this:

with these URLs which only works on localhost and can not be exposed to the outside world and that's why these URLs can not be used for setting up webhooks.

In order to receive webhook calls on your localhost you will need to create a tunnel in order to expose your application to the outside world and similarly receive request from outside as well.

In order to achieve that, there are multiple tools that can help you with that such as ngrok or expose

In this tutorial we will use ngrok to setup tunnel and will use http://sample-app.test as example localhost application.

Following are the steps:

Install the ngrok Agent

For MacOS:

brew install ngrok/ngrok/ngrok
Enter fullscreen mode Exit fullscreen mode

For Linux:

curl -s | \
      sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && \
      echo "deb buster main" | \
      sudo tee /etc/apt/sources.list.d/ngrok.list && \
      sudo apt update && sudo apt install ngrok
Enter fullscreen mode Exit fullscreen mode

For Windows, use Chocolatey:

choco install ngrok
Enter fullscreen mode Exit fullscreen mode

If you prefer to install the ngrok agent yourself, visit the ngrok Download page for instructions and links.

After the installation you can confirm the installation via the following command:

Enter fullscreen mode Exit fullscreen mode

and you should see:

   ngrok - tunnel local ports to public URLs and inspect traffic

    ngrok exposes local networked services behinds NATs and firewalls to the
    public internet over a secure tunnel. Share local websites, build/test
    webhook consumers and self-host personal services.
    Detailed help for each command is available with 'ngrok help <command>'.
    Open http://localhost:4040 for ngrok's web interface to inspect traffic.

    ngrok http 80                    # secure public URL for port 80 web server
    ngrok http -subdomain=baz 8080   # port 8080 available at
    ngrok http            # tunnel to host:port instead of localhost
    ngrok http https://localhost     # expose a local https server
    ngrok tcp 22                     # tunnel arbitrary TCP traffic to port 22
    ngrok tls 443  # TLS traffic for to port 443
    ngrok start foo bar baz          # start tunnels from the configuration file


  inconshreveable - <>

   authtoken    save authtoken to configuration file
   credits  prints author and licensing information
   http     start an HTTP tunnel
   start    start tunnels by name from the configuration file
   tcp      start a TCP tunnel
   tls      start a TLS tunnel
   update   update ngrok to the latest version
   version  print the version string
   help     Shows a list of commands or help for one command
Enter fullscreen mode Exit fullscreen mode

Start ngrok

Now you can create tunnel to your localhost sample-app.test via ngrok, use the following command:

ngrok http -host-header=sample-app.test
Enter fullscreen mode Exit fullscreen mode

and you should see the following:


Session Status                online
Account                       inconshreveable (Plan: Free)
Version                       3.0.0
Region                        United States (us)
Web Interface       
Forwarding           ->
Forwarding           ->

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00
Enter fullscreen mode Exit fullscreen mode

Now, you should be able to use either http ( or https ( version of the ngrok URL, which is now pointing to your localhost sample-app.test. This allows to you to share your localhost application with outside world or configure webhooks to receive their calls.

Use the follwoing URL: to see the incoming calls to your application. This also provides you away to replay the request calls and see their information as well.

Happy coding!

Top comments (0)