anumargak (अनुमार्गक)
Fastest HTTP Router


Usage
const router = require('anumargak')({
defaultRoute : defaultHandler,
ignoreTrailingSlash: true
});
anumargak.on("GET", "/this/is/static", handler);
anumargak.on(["POST","PUT"], "/this/is/static", handler);
anumargak.on("GET", "/this/is/:dynamic", handler);
anumargak.on("GET", "/this/is/:dynamic", handler);
anumargak.on("GET", "/this/is/:dynamic/with/:pattern(\\d+)", handler);
anumargak.on("GET", "/this/is/:dynamic/with/:two-:params", handler);
anumargak.on("GET", "/this/is/:dynamic/with/:two(\\d+):params", handler);
anumargak.on("GET", "/this/is/:dynamic/with/:two(\\d+)rest", handler);
anumargak.on("GET", "/similar/:string([a-z]{10})", handler);
anumargak.on("GET", "/similar/:number([0-9]{10})", handler);
anumargak.find("GET","/this/is/static");
anumargak.find("GET","/this/is/dynamic/with/123?ignore=me");
anumargak.lookup(req,res) ;
console.log(anumargak.count);
wildcard: I couldn't understand the need of wildcard, hence not implemented. Please raise the issue if it should be implemented.
Example with server
const http = require('http')
const router = require('anumargak')()
router.on('GET', '/', (req, res, params) => {
})
const server = http.createServer((req, res) => {
router.lookup(req, res)
})
server.listen(3000, err => {
if (err) throw err
console.log('Server listening on: http://localost:3000')
})
Benchmark
method | url type | anumargak (अनुमार्गक) | find-my-way |
---|
find | static | 27445088.79 | 3130047.682 |
find | dynamic | 2677420.545 | 1243596.976 |
find | dynamic with query | 1735442.647 | 1225523.327 |
find | enum | 25881565.6 | 1416613.461 |
lookup | static | 29077013.86 | 2400789.425 |
lookup | dynamic | 2030403.951 | 1101769.543 |
lookup | dynamic with query | 1419140.375 | 974787.2642 |
lookup | enum | 15906062.45 | 1191961.68 |
Note : Above benchmark has been taken on 16gb RAM ubuntu 17.10 machine with node v9.5.0 and npm v5.6.0

Worth to mention
- NIMN निम्न : Schema aware object compression. 60% more compressed than JSON. 40% more compressed than msgpack.
- imglab : Web based tool to label images for object detection. Use it to train dlib or other object detectors. Integrated with 3rd party libraries to speed up tp process and to make you lazy.
- fast-lorem-ipsum : Generate lorem ipsum words, sentences, paragraph very quickly. Pure JS implementation.
- stubmatic : A stub server to mock behaviour of HTTP(s) / REST / SOAP services. You can easily mock msgpack, and nimn data formats as well.
- fast-xml-parser : Pure JS implementation to parse XML to JSON, JS Object, or Nimn format. Parse back from JSON, JS Object to XML. Or just validate XML syntax.
- Grapes : Flexible Regular expression engine (for java) which can be applied on char stream. (under development)
- Muneem (मुनीम): A framework to write fast web services in easy way. Designed specially for developers, QAs, Maintainers, and BAs.