Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/egorguru/impetuous
Incredibly Impetuous Node.js Router
https://github.com/egorguru/impetuous
fast javascript map nodejs router speed tree
Last synced: 22 days ago
JSON representation
Incredibly Impetuous Node.js Router
- Host: GitHub
- URL: https://github.com/egorguru/impetuous
- Owner: egorguru
- License: mit
- Created: 2019-07-04T18:41:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-21T19:41:48.000Z (almost 5 years ago)
- Last Synced: 2025-01-03T20:49:05.986Z (22 days ago)
- Topics: fast, javascript, map, nodejs, router, speed, tree
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/EgorRepnikov/impetuous.svg?branch=master)](https://travis-ci.org/EgorRepnikov/impetuous)
[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/EgorRepnikov/impetuous/blob/master/LICENSE)# 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
```bash
$ npm install impetuous
```# How to Use?
```js
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](https://github.com/EgorRepnikov/dragonrend) uses Impetuous as Router. Extension example: [class Router](https://github.com/EgorRepnikov/dragonrend/blob/master/lib/routing.js)
# Author
**Egor Repnikov** - [GitHub](https://github.com/EgorRepnikov)# License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details