Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A small routing/web framework for Node

branch: master

Merge pull request #1 from mattneary/master

Regex Routing, Middleware Callbacks, Parameters Exposed, Chainable
latest commit ad7d9c7434
Dhaivat Pandya authored July 15, 2013
Octocat-spinner-32 lib tidying July 15, 2013
Octocat-spinner-32 Birbal.js
Octocat-spinner-32 README.md syntax highlighting July 15, 2013
Octocat-spinner-32 example.js
Octocat-spinner-32 package.json
README.md

Birbal

A clever little framework for Node.js

  • Provides regex- and string-based routing of requested URLs.
  • Parses HTTP query-string parameters and body parameters, exposed in handler callbacks as this.vars.
  • Allows for middleware, such as database queries or cookie parsing.
  • Has a simple chainable syntax.

Setup

You will want to include the Birbal module. Most likely, you will set the imported value to a convenient name, like app which is used throughout our examples.

var app = require("Birbal");

Routing

Routing is performed by use of Birbal#get, Birbal#post, etc. Usage is of the following form.

app.get(*path*, *handler*[, *middleware*]).post(...)

handler is a function of request, response, and any passed values of the middleware. middleware is a function of handler, request, and response. The following is an example of this all working together.

app.get('/', function(req, res, time) {
    res.end("hi, it's "+time+".");
}, function(handler, req, res) {
    handler((new Date()).getTime());
});

Request Variables

Request variables are exposed to handlers and middleware as this.vars. The following is an example of this at use.

app.get(/^/, function(req, res) {
    res.end("hi, "+this.vars.name);
});

Running a Server

http.createServer(app).listen(8080);
Something went wrong with that request. Please try again.