Using nGrok to test Azure Functions Locally
Testing code that has been written locally is always the best practice and is a habit every developer should cultivate from their junior programmer days. Testing local websites, applications and even APIs is pretty straightforward. But what if I need to call back to an API on my local machine and test that the call back is working. A classic example is payment gateways trying to call back an endpoint. You don't want to be constantly deploying little increments of code and changes for testing local work. In such instances, nGrok can be of great help. nGrok opens up secure tunnels to your local development machine.
Recently, I have been investigating Actions on Google and DialogFlow and how to enable fulfillment using an HTTPS webhook. I wrote an Azure Function to receive the call from the DialogFlow webhook but I didn't want to deploy it before testing it. So I used nGrok to consume the DialogFlow webhook.
To use nGrok to consume Webhook locally, download the executable from their website. I did not set up an account myself but I guess it can be very useful if you want to see the dashboard and longer timeouts. To set up a secure tunnel to test my Azure Function, I begin with a debugging session which gives me the url to my Azure Function.
Then I ran nGrok.exe and use the following command to start a HTTP tunnel to my local Azure Function
ngrok http http://localhost:7071
This will set up the tunnel and give me a HTTP as well as HTTPS url which I can input into my DialogFlow console to test fulfillment.