HTTP Path Tree Router

2.0.1 · abandoned · verified Wed Apr 22

http-hash is an HTTP router for Node.js that organizes routes into a strict path tree structure, enabling resolution independent of definition order. Unlike traditional regex-based routers where route order can affect matching, http-hash segments paths (e.g., `/foo/bar` becomes `foo > bar`) to build a tree, supporting static segments, named parameters (`:param`), and splats (`*`). This approach simplifies reasoning about route precedence. The current stable version is 2.0.1, last published approximately 7 years ago (as of April 2026), indicating a long-abandoned project with infrequent or no further development. It primarily targets CommonJS environments.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create an http-hash router, define routes with named parameters and splats, and retrieve route information, including handling missing routes.

const HttpHash = require('http-hash');

// Create a new http hash instance
const hash = HttpHash();

// Define a route with a named parameter
hash.set('/test/:foo/', (req, res) => {
    res.end(`Hello from /test/${req.params.foo}`);
});

// Define a route with a splat parameter
hash.set('/files/*', (req, res) => {
    res.end(`Serving file: ${req.splat}`);
});

// Get and use a valid route
let route1 = hash.get('/test/variable-value');
console.log('Route 1 Handler:', route1.handler ? 'Found' : 'Not Found');
console.log('Route 1 Params:', route1.params); // { foo: 'variable-value' }

// Get and use a splat route
let route2 = hash.get('/files/path/to/document.txt');
console.log('Route 2 Handler:', route2.handler ? 'Found' : 'Not Found');
console.log('Route 2 Splat:', route2.splat); // path/to/document.txt

// Get an invalid route
let missingRoute = hash.get('/non-existent');
console.log('Missing Route Handler:', missingRoute.handler ? 'Found' : 'Not Found'); // Not Found

view raw JSON →