6.1.0 • Published 4 years ago

server-router v6.1.0

Weekly downloads
33
License
MIT
Repository
github
Last release
4 years ago

server-router stability

npm version build status test coverage downloads js-standard-style

Performant radix-trie router for streaming servers.

Usage

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()

API

router = serverRouter(opts)

Create a new router with opts.

router.route(method|methods, route, function (req, res, params))

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.

router.match(req, res)

Match a route on a router.

handler = router.start()

Return a function that can be passed directly to http.createServer() and calls router.match().

Installation

$ npm install server-router

See Also

License

MIT

6.1.0

4 years ago

6.0.0

7 years ago

5.2.0

7 years ago

5.1.0

7 years ago

5.0.0

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.9

8 years ago

1.1.8

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago