server-router
Version:
74 lines (58 loc) • 2.42 kB
Markdown
[![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7]
[![downloads][8]][9] [![js-standard-style][10]][11]
Performant [radix-trie](https://en.wikipedia.org/wiki/Radix_tree) router for
streaming servers.
```js
var serverRouter = require('server-router')
var http = require('http')
var router = serverRouter({ default: '/404' })
router.route('GET', '/hello', function (req, res, params) {
res.end('hello world')
})
router.route('PUT', '/hello/:name', function (req, res, params) {
res.end('hi there ' + params.name)
})
router.route('', '/404', function (req, res, params) {
res.status = 404
res.end('404')
})
http.createServer(router.start()).listen()
```
Create a new router with opts.
Register a new route with an HTTP method name and a routename. Can register
multiple handlers by passing an array of method names. `params` contains
matched partials from the route.
Match a route on a router.
Return a function that can be passed directly to `http.createServer()` and
calls `router.match()`.
```sh
$ npm install server-router
```
- [wayfarer](https://github.com/yoshuawuyts/wayfarer) - vanilla radix-trie
router
- [nanorouter](https://github.com/yoshuawuyts/nanorouter) - client-side
radix-trie router
[](https://tldrlegal.com/license/mit-license)
[]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
[]: https://nodejs.org/api/documentation.html#documentation_stability_index
[]: https://img.shields.io/npm/v/server-router.svg?style=flat-square
[]: https://npmjs.org/package/server-router
[]: https://img.shields.io/travis/yoshuawuyts/server-router/master.svg?style=flat-square
[]: https://travis-ci.org/yoshuawuyts/server-router
[]: https://img.shields.io/codecov/c/github/yoshuawuyts/server-router/master.svg?style=flat-square
[]: https://codecov.io/github/yoshuawuyts/server-router
[]: http://img.shields.io/npm/dm/server-router.svg?style=flat-square
[]: https://npmjs.org/package/server-router
[]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[]: https://github.com/feross/standard
[]: https://github.com/yoshuawuyts/wayfarer