Backend Discussion Featured Laravel NodeJS Others

Ngrok for webhook testing.

When you develop your web applications, you will have situation to test 3rd party API integration in the local development environment.

The tricky problem here is most of 3rd party APIs are callback based. In a word, most of 3rd party APIs send data/status as callbacks/webhook to original client. However when you wants to test on local environment, it’s impossible to receive webhook from them.

For example, in my case I had a situation to test webhook from CoinPayments API after making crypto deposit to the wallet.
At the first time, I was going to upload the project on test server and set the IP address on CoinPayments so that I can receive webhook into the test server.

But it’s as simple as you just need to leverage ngrok for the development environment.

Ngrok is a useful tool for developers to be able to expose their local dev server to public internet.

I ran my web backend on localhost:3000 and installed ngrok on my local pc.
After then, ran this command

ngrok http 3000

This ran ngrok up with public domain (with random string) and made it listening all the external requests to localhost:3000 and forwarding them to 3000 port.

Session Status                online                                                                                                                                        
Account                       Smart Dice (Plan: Free)                                                                                                                       
Version                       2.2.8                                                                                                                                         
Region                        United States (us)                                                                                                                            
Web Interface                 http://127.0.0.1:4040                                                                                                                         
Forwarding                    http://c5e79674.ngrok.io -> localhost:3000                                                                                                    
Forwarding                    https://c5e79674.ngrok.io -> localhost:3000                                                                                                   
                                                                                                                                                                            
Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                   
                              0       0       0.00    0.00    0.00    0.00  

Now, I just could use the public domain on CoinPayments webhook settings and tested BTC deposit, and I could inspect external requests to the domain on http://127.0.0.1:4040

Yay!! After few minutes I noticed a webhook request from CoinPayments from the inspector and my local pm2 logs.
This method really helped my development and I used this for other development that needed to test 3rd party API integrations.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *