Performant radix-trie router for streaming servers.
var serverRouter = require('server-router')
var http = require('http')
var router = serverRouter()
router.route('GET', '/hello', function (req, res, ctx) {
res.end('hello world')
})
router.route('PUT', '/hello/:name', function (req, res, ctx) {
res.end('hi there ' + ctx.params.name)
})
http.createServer(router.start()).listen()
Create a new router with opts:
- default: (default:
'/404'
) Path to default to when a route is not matched. If no default path is set, the router will crash when an unknown path is encountered.
Register a new route. ctx
is an object with .params
property that contains
any params. It's safe to extend ctx
with other values for the duration of the
request.
Match a route on a router.
Return a function that can be passed directly to http.createServer()
and
calls router.match()
.
$ npm install server-router
- wayfarer - vanilla radix-trie router
- nanorouter - client-side radix-trie router