Turnout

http url router

This project is maintained by ramitos

turnout

Build Status

usage

var router = require('turnout')()

require('http').createServer(function (req, res) {
    router(req, res, function () {
      res.statusCode = 404
      res.end()
    })
}).listen()

router.post('/todo/:id', function (req, res, params, query) {})

router.put('/todo/:id/:state', function (req, res, params, query) {})

router.get('/user/:id', function (req, res, params, query) {})

router.del('/user/:id', function (req, res, params, query) {})

install

$ npm install turnout

test

$ npm test

api

methods

get
router.get('/', callback)
post
router.post('/', callback)
put
router.put('/', callback)
delete
router.del('/', callback)

path

path
router.get('/todo/:id', callback)
regexp
router.get(/\/todo\/(\d*?)/, callback)

params

router.get('/todo/:id', function (req, res, params) {
  assert(params.id === '5')
})

request.get('http://address:port/todo/5')

query

router.get('/todos/:state', function (req, res, params, query) {
  assert(query.priority === 'urgent')
})

request.get('http://address:port/todo/completed?priority=urgent')

credits

license

Copyright (C) 2012 Sérgio Ramos <mail@sergioramos.me>

Permission is hereby granted, free of charge, to any person obtaining a copy of 
this software and associated documentation files (the "Software"), to deal in 
the Software without restriction, including without limitation the rights to 
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
of the Software, and to permit persons to whom the Software is furnished to do 
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.