npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

httphooks

v0.0.1

Published

A webhook implementation which extends the concept to HTTP REST API's

Downloads

2

Readme

httphooks

In this world of internet of things, we have realized that while there are multiple frameworks, protocols and standards that allow you to intercommunicate between different devices none is more prevalent than the actual ones exposed by and defined through the web. For this reason, this module has the intent of standardizing using HTTP, REST and web sockets with the intent to facilitate connecting logic and data while maintaining its distribution and facilities.

httphooks is a node HTTP pub-sub architecture that allows you to associate an incoming HTTP request to a single/multiple dependent/independent user defined operations. These operations work in a loosely coupled manner such that together, with a well defined execution model, each collaborate in order to deliver a result. httphooks extends the webhooks model to the primary REST HTTP verbs and formalizes request/response, inter-communication and signaling using HTTP as the communication standard.

While there are existing and similar modules (a.k.a middleware), we have a pretty interesting architecture, model and set of features that are not present in others and which allow you to streamline your development. Don't be shy and take a look at our documentation, you just might be pleasantly surprised...

Installation

npm install httphooks

Tests

Running the tests

The test suite can be invoked from the command line like this:

npm test

Some details about the tests

In order to successfully run the tests three environment variables are used for setting the port numbers: PORT, PORT1 and PORT2.

  • PORT and PORT1 default to 8080
  • PORT2 defaults to 8081

For now, if you want to use different port numbers, you'll have to modify the values in the ./tests/runTests.js file. When time permits we'll change this so it can be done in some other manner (i.e. via a JSON file, command-line options, etc.).

Usage

With httphooks you are able to associate logical units for execution with url paths with a given HTTP verb.

var http = require('http');
var HttpHooks = new require('httphooks');
var hooks = new HttpHooks();

// Respond to any incoming requests with a hello world message which includes the url path
hooks.get('/*', function (hookContext, done) {
    var request = hookContext.request;
    var response = hookContext.response;
    hookContext.setResponse(
        200,
        { 'Content-Type': 'text/html' },
        'Welcome to \'' + request.url.path + '\'... Hello World! :)');
    done();
});

var server = http.createServer(function (request, response) {
    hooks.dispatch({request: request, response: response});
});

server.listen(8080);

Features

  • Integrates and standardizes on default primitives defined by the HTTP protocol.
  • Interfaces with node.js http server and both sockjs and socket.io.
  • By default, supports the four main HTTP verbs: GET, PUT, POST and DELETE.
  • Leverages route-pattern to define the resource locations to hook on.
  • Well defined execution and inter-communication model for logical units.
  • Clean separation between listener and responder for compute or I/O logical units.
  • Inline, file (e.g. 'file:') or remote (e.g. 'http:', 'https:' or 'ws:') hook definition of logical execution units.
  • Default responder support allowing any request to be serviced when no matching hook is found.
  • Handling of non-matching requests to hooks (when no default responder is set).
  • Supports detection and collapsing of multiple responses into a single multipart response (by default).
  • Large amount of documentation including design, common use patterns, code examples and API references.
  • Large test suite exercising features.

Documentation