DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • The Native Way To Configure Path Aliases in Frontend Projects
  • RBAC With API Gateway and Open Policy Agent (OPA)
  • Multi-Stream Joins With SQL
  • Testing, Monitoring, and Data Observability: What’s the Difference?
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Test Incoming Webhooks Locally with Ngrok

Test Incoming Webhooks Locally with Ngrok

Lorna Mitchell user avatar by
Lorna Mitchell
·
Mar. 29, 15 · Interview
Like (0)
Save
Tweet
Share
5.60K Views

Join the DZone community and get the full member experience.

Join For Free

I'm enjoying working with hubot; I have a few different instances running for different groups. One of the things that I use hubot for is to echo activities from the source control repo, the bug tracker, the CI system, the (you get the idea) into the channel for a project. This is achieved via webhooks; a feature offered by many providers to POST information about an event to your endpoint as soon as it happens.

In this case, the webhook points to the hubot code running on heroku, which isn't an ideal place to debug a problem or fiddle about getting a message wording just right with all the fields in place. Instead, I do all that locally using the hubot and its shell adapter. How? Using Ngrok!

Ngrok Opens Localhost

Ngrok is a command you run locally, which opens a tunnel on the port you specify from your machine to the outside world. Ngrok will then make an incoming tunnel available and let you know which URL to use - ideal for allowing people to inspect development versions of your websites, or for testing incoming webhooks against a local dev platform.

Hubot runs on port 8080 by default so I start the tunnel with this command:

ngrok 8080

Ngrok gets going and presents a kind of commandline console view:

Screenshot from 2015-03-11 08:17:25

When requests start coming through, you'll see them listed here, but there are two important pieces of information that we want to grab at this point. One is the "Web Interface" URL, usually http://127.0.0.1:4040, which you can open in your browser - we'll revisit this in a bit. The most important one is the "Forwarding" URL. Requests to this endpoint will end up on your machine on the port you specified.

As an example, today I'm doing some testing with the webhooks that come in from GitHub. I didn't find that the support in existing hubot plugins was great, so I forked an existing one and added some functionality to it (you can find my plugin here, try the "joindin-hubot" branch: https://github.com/lornajane/hubot-github-repo-event-notifier). To test, I edited the webhooks on my repo to instead point to the URL ngrok gave me, so for this plugin, the webhook endpoint is now: http://42aa88bf.ngrok.com/hubot/gh-repo-events.

Screenshot from 2015-03-11 08:36:36

Then I trigger a hook to fire, and see what my hubot does. Probably, it might need a bit of fine tuning, so I can edit the code on my local machine, run the bot again, and repeat. Even better, check out the "Web Interface" link that ngrok produces - this has full details of all the requests we received and responded to. It also allows you to replay requests, so once you've triggered a webhook once you can just replay as many times as you need to (actually GitHub in particular have excellent replay features on their webhook pages, but not all providers do).

Screenshot from 2015-03-11 08:40:17

One you're happy, shut down your ngrok tunnel with Ctrl+c, and you can commit and push your changes to your live hubot. I find this technique incredibly helpful, and hopefully you do too! If you have anything to add, please leave me a comment, I think these toolchains are improving all the time so it would be great to hear how others are approaching the same problems or tools.

Webhook Testing

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • The Native Way To Configure Path Aliases in Frontend Projects
  • RBAC With API Gateway and Open Policy Agent (OPA)
  • Multi-Stream Joins With SQL
  • Testing, Monitoring, and Data Observability: What’s the Difference?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: