httphooks

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

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...

npm install httphooks

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

npm test

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.).

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 (hookContextdone) {
    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 (requestresponse) {
    hooks.dispatch({request: request, response: response});
});
 
server.listen(8080);
  • 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.