impetuous
v0.3.1
Published
Incredibly Impetuous Node.js Router
Downloads
14
Maintainers
Readme
Impetuous
Impetuous is simple and fast Node.js Router for building web applications.
Impetuous uses Map and the freestyle implementation of Radix Tree for different types of routes. Due to this you achieve very high speed in all cases.
Installation
$ npm install impetuous
How to Use?
const http = require('http')
const Impetuous = require('impetuous')
const router = new Impetuous()
// Third handler argument can be, what you want
router.add('GET', '/path', () => {
// Handle something
})
router.add('POST', '/path', () => {
// Handle something
})
// Third handler argument can be, what you want
router.add('DELETE', '/path/:param', [
() => {
// Handle something
},
() => {
// Handle something
}
])
router.find('GET', '/path')
// -> { handler: [Function] }
router.find('GET', '/path/') // <- '/' at the end works
// -> { handler: [Function] }
router.find('POST', '/path')
// -> { handler: [Function] }
router.find('DELETE', '/path/123')
// -> { handler: [[Function, Function]], params: { param: 123 } }
API
add(method: String, path: String, handler: Any)
Adds a new handler for the method and path.
find(method: String, path: String)
Finds the handler for the method and path.
Returns Object with the following fields:
handler: Any
what you added
params: Object
contains params from path /path/:param
<- like this
Usage Example
Library/Framework Dragonrend uses Impetuous as Router. Extension example: class Router
Author
Egor Repnikov - GitHub
License
This project is licensed under the MIT License - see the LICENSE file for details