ika

unfancy url routing

npm install ika
5 downloads in the last week
20 downloads in the last month

イカ

braindead routes.

var routes = require('ika').routes
routes.add('GET', /\/borges\/(\w+)\//, function(book) {
    this.res.writeHead(200, {'Content-Type':'text/plain'})
    if (book === 'babel') {
        this.res.end('a triangular room is inconceivable')
    }
    else {
        this.res.end('no such book')
    }
})

routes.add('POST', '/borges/add/', function() {
   // do work 
})
var server = http.createServer(function(req, res) {
    routes.route(req, res)
})
  • pass a regex literal or a string
  • req and res are properties in the context of the callback
  • captured args in regex are passed as params to callback
  • that's it.

meta

ika was written by nathaniel k smith nathanielksmith@gmail.com and is licensed under the terms of the GPL3.

npm loves you