webhook-manager

    1.0.2 • Public • Published

    Webhook-Manager

    This is a lightweight npm-package to manage webhook-listeners.

    What WebHooks are used for

    Webhooks are "user-defined HTTP callbacks". They are usually triggered by some event, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URI configured for the webhook. Users can configure them to cause events on one site to invoke behaviour on another. The action taken may be anything. Common uses are to trigger builds with continuous integration systems or to notify bug tracking systems. Since they use HTTP, they can be integrated into web services without adding new infrastructure.

    Installation

    npm i -s webhook-manager

    How it works

    To receive webhooks, we basically just need to setup a webserver and start listening for incomming POST-requests. This is, what this plugin does.

    We setup an express-server on a specific port and then start listening for all incomming POST-requests. The requests get filtered, if a webhook is listening for it - if yes, then an event to this registered webhook gets emitted.

    Usage

    // Import the package
    const WebhookManager = require("webhook-manager");
     
    // Create a new instance of the Webhook-Manager with a specific port to listen on
    const manager = new WebhookManager(4848);
     
    // Just a listener for the "ready"-event
    // It get's fired, when the manager is setup properly
    manager.on("ready", () => {
        console.log(`WebhookManager started on port :${manager.PORT}`);
    });
     
    // Register a new Webhook-Listener
    // It listens for everything, that goes directly to 'http://YOUR_SERVER:PORT/webhook
    // The callback gets fired, when a webhook is received
    //      'data' is the request, received by the listener
    manager.on("/webhook", data => {
        console.log("Received webhook with following data:", data);
    });

    Install

    npm i webhook-manager

    DownloadsWeekly Downloads

    3

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    5.68 kB

    Total Files

    4

    Last publish

    Collaborators

    • h1ghbre4k3r