DEV Community

Adam Smolenski
Adam Smolenski

Posted on

Need to test API webhooks on local host? ngrok is a great solution.

So recently I was trying to incorporate the mailgun api to keep track of user engagement with emails (did they just toss them out, like I usually do for certain mailing lists". So I wanted to add the built-in opened event from mailgun. But before deploying it into the real world I was trying to figure out how to get the webhook locally... You can't very well add localhost:3000 to the webhook, that just won't work.

Enter ngrok. It's a simple little tool that allows IP tunneling. So when you run the program, it will generate a secure url that will forward to your local host.

It's extremely simple and free for small use cases like mine was. It was limited to 40 connections a minute. So heck, I'd just keep my tests slow paced. The only thing I had to remember was in the end I was using a subdomain so that was just adjusting my routes on deploy. But on the $5/month plan it's quite simple.

To get started all you have to sign up. Download ngrok, on the mac I had to allow my terminal to open it. Mac has some fun security these days. But after you download you should unzip the file somewhere you will remember to access it. I put it in the base folder of the project I needed it, since it's a tool that will be commonly associated with these files.

When you finish that, ngrok will assign an auth token with your account. In the folder you threw ngrok file in you can just enter ./ngrok authtoken YOUR_TOKEN_HERE.
After that you are pretty much done. All you have to type in the terminal after that is ./ngrok http https://localhost:3000. You can throw in whatever port you want. I was using rails so 3000 was my backends default. After running that function, it will give you an informational display. It will give you the internet address in a form of https://SOMETHING.ngrok.io log request types and where they were headed. When I saw my POST request to /notification from mailgun popping in I was delightfully surprised at the ease of adding this new test tool to my arsenal. It also means I can also test outside network devices for other projects and just see how they load differently depending on networks.

For something so easy to implement it is vastly useful. Hopefully it's a useful program for you to use.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay