Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including houkou with all npm packages installed. Try it out:

var houkou = require("houkou")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

houkou v0.2.2

Teeny tiny router for node and the browser

Houkou

Teeny tiny router for node and the browser

Overview

Houkou is a very simple (but surprisingly featureful) router written in JavaScript, targeted towards both Node.JS and the browser. It has no external dependencies and currently weighs in at just over a kilobyte uncompressed.

Features

  1. Simple, clear syntax
  2. Named route parameters
  3. Custom parameter regexes
  4. Reverse routing (generate urls from routes)
  5. Fully tested (check test directory)

Users

  • wham - "whimsical web framework"
  • contact me to get your package listed!

Documentation

There's not much to be documented, fortunately! The example below should cover just about everything (seriously). There's some tests in the test directory as well if you want some more examples.

Example Usage

Code:

var Houkou = require("houkou");

// create a new route
var route = new Houkou("/post/:id/:title", {requirements: {id: "[0-9]+"}});

// parse a url according to our route definition
var params = route.match("/post/123/this-is-an-example-post");

// print it out all pretty-like
console.log("Parsed:");
console.log(params);
console.log("");

// construct a url using our route as a template, filling in the variables with
// those supplied
var url = route.build(params);

// dump!
console.log("Generated:");
console.log(url);
console.log("");

Output:

Parsed:
{ id: '123', title: 'this-is-an-example-post' }

Generated:
/post/123/this-is-an-example-post

License

3-clause BSD. A copy is included with the source.

Contact

  • GitHub (http://github.com/deoxxa)
  • Twitter (http://twitter.com/deoxxa)
  • Email (deoxxa@fknsrs.biz)

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free