ravine

ravine is a simple router middleware for nodejs

ravine

ravine is a simple router middleware for nodejs

with ravine routes are just javascript arrays. use javascript array manipulation functions to construct and manipulate routes.

npm install ravine
http = require 'http'
 
ravine = require 'ravine'
 
middleware = ravine [
    ['ALL''*'(req, res, next) ->
        # called before all following routes 
        next()
    ]
    ['GET''/'(req, res, next) ->
        # called only on GET / 
        res.end 'hello'
    ]
    ['ALL''/users*'(req, res, next) ->
        # called before all following routes if the request url starts with /users 
        next()
    ]
    ['POST''/users'(req, res, next) ->
        res.end 'post'
    ]
    ['PUT''/users/:id'(req, res, next) ->
        # called on PUT /users/7 for example. req.params will then be {id: 7} 
        res.end 'put ' + req.params.id
    ]
    ['DELETE''/users/:id'(req, res, next) ->
        # called on DELETE /users/18 for example. req.params will then be {id: 18} 
        res.end 'delete ' + req.params.id
    ]
]
 
server = http.createServer middleware
 
server.listen 80

see url-pattern for supported url patterns. the parameters extracted from the url will be available as req.params.