DEV Community

Cover image for How to Get a Webhook Online: A Developer's Guide
Robbie Cahill
Robbie Cahill

Posted on • Originally published at softwareengineeringstandard.com

How to Get a Webhook Online: A Developer's Guide

Introduction to Online Webhooks

In modern web development, services frequently need to communicate with each other in real-time. While APIs allow your application to request data from other services, webhooks reverse this flow, enabling services to send data to your application as events happen. Whether it's a payment confirmation from Stripe, a new commit notification from GitHub, or a custom event from an IoT device, webhooks are the engine of the event-driven web.

However, there's a fundamental challenge developers face when working with webhooks: the service sending the webhook needs to reach your application over the internet. This means your application must have a public, "online" URL. During development, your application is typically running on localhost, a private address accessible only from your own computer.

So, how do you get your localhost server online to receive and test webhooks?

This guide will walk you through what it means for a webhook to be "online," why localhost isn't enough, and how you can use Tunnelmole, an open-source tool, to create a secure, public URL for your local development environment. By the end, you'll be able to receive, test, and debug webhooks directly on your machine, dramatically speeding up your development workflow.

What Exactly is a Webhook? The "Reverse API" Explained

If you're new to the concept, the easiest way to understand a webhook is to think of it as a "reverse API."

  • With a standard API, you (the client) initiate a request to a server to get or send data. For example, you might make a GET request to https://api.weather.com/latest to fetch the current weather. You are in control of when the request is made.
  • With a webhook, the roles are flipped. The external service (the webhook provider) initiates a request to your application's endpoint whenever a specific event occurs. You don't ask for the data; the provider pushes it to you.

This push model is incredibly efficient. Your application doesn't need to constantly poll an API endpoint asking, "Has anything new happened yet?" This saves network bandwidth, reduces server load for both you and the provider, and provides data in near real-time.

Common Use Cases for Webhooks

You'll find webhooks used in countless scenarios across the web:

  • Payment Gateways (Stripe, PayPal): Receive instant notifications for successful payments, failed transactions, or new subscriptions.
  • Version Control (GitHub, GitLab): Trigger CI/CD pipelines automatically when code is pushed to a repository.
  • Communication Platforms (Slack, Twilio): Build bots that react to messages or receive notifications about incoming calls and SMS messages.
  • eCommerce (Shopify): Update inventory systems or notify shipping departments when a new order is placed.
  • Automation Services (IFTTT, Zapier): Connect different apps and services to create powerful, automated workflows.

In all these cases, the provider needs a stable, public URL—a "webhook online" endpoint—to send its HTTP POST requests to.

The localhost Problem: Why Your Dev Server Isn't Online

When you're building a web application, you typically run it on your local machine. You might start a Node.js server that listens on http://localhost:3000 or a Python server on http://127.0.0.1:8000. These addresses are special; they point back to your own computer. This is perfect for development because it's fast, secure, and doesn't require an internet connection.

However, from the perspective of an external service like Shopify or GitHub, localhost is meaningless. When Shopify tries to send a webhook to http://localhost:3000/shopify-webhooks, its servers will try to connect to their own localhost, not yours.

Your development machine is usually sitting behind multiple layers of networking, including:

  1. Network Address Translation (NAT): Your home or office router uses NAT to manage multiple devices on a private network with a single public IP address. It doesn't know which device to send an unsolicited incoming request to.
  2. Firewalls: Your operating system and network router have firewalls that are configured by default to block almost all incoming connections for security reasons.

To make your local server accessible, you would traditionally have to deploy your code to a public server or configure complex network settings like port forwarding. This is slow, tedious, and a major roadblock to efficient development.

Solution: Get Your Webhook Online in Minutes with Tunnelmole

This is where a tunneling tool like Tunnelmole comes in. Tunnelmole is a simple, open-source command-line tool that creates a a secure tunnel from a public URL on the internet directly to your localhost server. It bridges the gap between the public internet and your private development environment, effectively putting your webhook endpoint "online."

Let's walk through the process step-by-step.

Step 1: Create a Basic Webhook Listener in Node.js

First, you need an application to receive the webhook. Let's create a very simple one using Express.js, a popular Node.js framework. If you don't have a Node.js project, create one:

mkdir webhook-listener
cd webhook-listener
npm init -y
npm install express
Enter fullscreen mode Exit fullscreen mode

Now, create a file named index.js and add the following code:

const express = require('express');
const app = express();
const port = 3000;

// Middleware to parse JSON bodies. Most webhooks send data in JSON format.
app.use(express.json());

// Define our webhook endpoint
app.post('/webhook-handler', (request, response) => {
    console.log('🎉 Webhook Received!');

    // The data sent by the provider is in the request body
    const { body, headers } = request;
    console.log('Headers:', JSON.stringify(headers, null, 2));
    console.log('Body:', JSON.stringify(body, null, 2));

    // It's crucial to send a 200 OK response quickly
    // to let the provider know you've received the webhook.
    response.status(200).send('Webhook received successfully.');
});

app.listen(port, () => {
    console.log(`Webhook listener started on http://localhost:${port}`);
});
Enter fullscreen mode Exit fullscreen mode

This code does three key things:

  1. It starts a web server on localhost, port 3000.
  2. It uses express.json() middleware to automatically parse incoming JSON payloads.
  3. It defines an endpoint at /webhook-handler that listens for POST requests, logs the received data, and sends back a 200 OK status.

Run the application:

node index.js
Enter fullscreen mode Exit fullscreen mode

You'll see the message: Webhook listener started on http://localhost:3000. Your server is running, but it's not yet online.

Step 2: Install Tunnelmole

Next, install Tunnelmole. It's a native NodeJS application and can be installed via NPM or a simple script.

For Linux, macOS, or Windows Subsystem for Linux (WSL):
The easiest way is to run the installation script.

curl -O https://install.tunnelmole.com/xD345/install && sudo bash install
Enter fullscreen mode Exit fullscreen mode

Using NPM (requires Node.js):
If you have Node.js installed, you can use npm.

sudo npm install -g tunnelmole
Enter fullscreen mode Exit fullscreen mode

For Windows:
Download tmole.exe and place it in a folder that's included in your system's PATH.

Step 3: Launch Tunnelmole to Go Online

With your Node.js server running in one terminal, open a new terminal and run Tunnelmole. Point it to the port your application is listening on (in our case, 3000).

tmole 3000
Enter fullscreen mode Exit fullscreen mode

Tunnelmole will connect to its service and generate a public URL. The output will look something like this:

Your Tunnelmole Public URLs are below and are accessible internet wide. Always use HTTPs for the best security

https://k8sjer-ip-12-34-56-78.tunnelmole.net ⟶ http://localhost:3000
http://k8sjer-ip-12-34-56-78.tunnelmole.net ⟶ http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

That's it! The HTTPS URL is now your public webhook endpoint. You can now use this URL in any webhook provider's settings. For our example, the full URL would be:

https://k8sjer-ip-12-34-56-78.tunnelmole.net/webhook-handler

Any request sent to this URL will be securely tunneled to your Express app running on localhost:3000.

How Tunnelmole Makes Your Webhook Online

Tunnelmole's architecture is designed to be simple and effective. The diagram below illustrates how it works:

How Tunnelmole works

  1. Client Connection: The tmole client on your machine establishes a persistent, outbound connection to the Tunnelmole service running on a public server. This connection is typically a WebSocket, which works even behind most firewalls and NATs because it's initiated from inside your network.
  2. Public URL Generation: The Tunnelmole service assigns a unique public URL (e.g., https://k8sjer-....tunnelmole.net) and associates it with your client's connection.
  3. Incoming Webhook: When a webhook provider (like GitHub) sends a request to your public URL, the request first hits the Tunnelmole service.
  4. Tunneling: The service immediately forwards the entire HTTP request (headers, body, and all) through the established tunnel to the Tunnelmole client on your machine.
  5. Local Forwarding: The client receives the request and forwards it to your local server (e.g., http://localhost:3000).
  6. Response Path: Your local server processes the request and sends a response (e.g., a 200 OK). This response travels back through the exact same path: from your server to the tmole client, through the tunnel to the service, and finally back to the original webhook provider.

This entire process happens in seconds, allowing for a seamless, real-time development experience.

Open Source and Self-Hosting: Taking Full Control

One of the most significant advantages of Tunnelmole is that it's fully open source. Both the client you run locally and the server that manages the tunnels are available on GitHub. This provides several key benefits:

  • Transparency and Security: You can audit the code yourself to understand exactly what it's doing. There are no black boxes. For teams working in high-security environments, this is a non-negotiable feature.
  • Customization: If you need specific features or integrations, you can fork the project and modify it to suit your needs.
  • Self-Hosting: While Tunnelmole offers a convenient hosted service, you are not locked into it. You can deploy the Tunnelmole service on your own infrastructure (e.g., AWS, a VPS, or even a Raspberry Pi). Self-hosting gives you complete control over your data privacy, domain names, and operational stability. You can use custom subdomains without a subscription.

The Ultimate Workflow: Debugging Webhooks with Breakpoints

The ability to get a webhook online and route it to your local machine enables the most powerful debugging technique of all: breakpoints.

Instead of adding endless console.log statements, you can set a breakpoint in your IDE (like Visual Studio Code) right inside your webhook handler function.

  1. Set a breakpoint on the first line inside your /webhook-handler in index.js.
  2. Start your application in debug mode in your IDE.
  3. Trigger a webhook from your provider (e.g., by making a push in GitHub or using a tool like Postman to send a request to your Tunnelmole URL).

When the webhook is sent, the execution of your code will pause at the breakpoint. From there, you can:

  • Inspect the entire request payload: View the webhook body and headers in their raw, unprocessed form.
  • Step through your code: Execute your logic line-by-line to see how it behaves.
  • Check variable states: Examine the values of variables at any point in the process.
  • Identify errors instantly: See exactly where your code fails or behaves unexpectedly.

This level of interactive, real-time debugging is impossible if you have to deploy your code to a remote server for every change. It transforms webhook development from a frustrating guessing game into a streamlined, efficient process.

Conclusion

Understanding how to get a webhook "online" is a critical skill for any modern developer. While the complexities of internet networking can make it seem daunting, tools like Tunnelmole abstract away the difficulty, allowing you to focus on what matters: building and testing your application's logic.

By creating a secure tunnel from a public URL to your localhost server, Tunnelmole enables you to:

  • Receive and test webhooks from any provider directly on your development machine.
  • Debug your code interactively with breakpoints for a fast and efficient workflow.
  • Share your work with colleagues or clients before its deployed.
  • Leverage an open-source tool that you can audit, customize, and even self-host for maximum control.

The next time you're tasked with integrating a webhook, you'll know exactly how to bring it online to your local environment, saving you hours of time and frustration.

Top comments (0)