koa-flexrouter
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

koa-flexrouter

flexrouter implement in koa

NPM version build status coverage

Performance

Compared to koa-router, find-my-way, it has a similar performance result when there're 50 routes. When increase route to 2401, the performance result:

codespace ➜ /workspaces/koa-flexrouter/benchmark (master ✗) $ node index.js 
benchmark home path: '/', and a random path: '/cndhomeainrmsfbn/1/wxcfkdikzb'
koa-router#topic-detail x 944 ops/sec ±122.08% (93 runs sampled)
flexrouter#topic-detail x 2,887,212 ops/sec ±1.10% (93 runs sampled)
find-my-way#topic-detail x 1,079,235 ops/sec ±6.18% (87 runs sampled)

codespace ➜ /workspaces/koa-flexrouter/benchmark (master ✗) $ node index.js 
benchmark home path: '/', and a random path: '/nblqjipdz/1/'
koa-router#topic-detail x 959 ops/sec ±121.41% (94 runs sampled)
flexrouter#topic-detail x 4,112,523 ops/sec ±1.21% (89 runs sampled)
find-my-way#topic-detail x 1,847,886 ops/sec ±1.22% (96 runs sampled)

codespace ➜ /workspaces/koa-flexrouter/benchmark (master ✗) $ node index.js 
benchmark home path: '/', and a random path: '/xeyk/1/avdegacnmiesgk'
koa-router#topic-detail x 977 ops/sec ±119.90% (92 runs sampled)
flexrouter#topic-detail x 2,550,022 ops/sec ±0.92% (93 runs sampled)
find-my-way#topic-detail x 1,343,876 ops/sec ±0.66% (94 runs sampled)

Installation

npm i koa-flexrouter

Usage

import Router from 'koa-flexrouter';
import * as Koa from 'koa';

const router = new Router();
const app = new Koa();

router.get('/test', async (ctx, next) => {

})

router.post('/test', async (ctx, next) => {

})

app.use(router.routes())

sub-router

import Router from 'koa-flexrouter';
import * as Koa from 'koa';

const router = new Router();
const app = new Koa();

var subRouter = router.group({
    path: '/sub',
    middlewares: [
        async (ctx, next) => {
            return next();
        },
        async (ctx, next) => {
            return next();
        },
    ]
})

subRouter.get('/:id/xxx', async (ctx, next) => {

})

subRouter.post('/:id/*action', async (ctx, next) => {

})

app.use(router.routes())

Package Sidebar

Install

npm i koa-flexrouter

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

51 kB

Total Files

13

Last publish

Collaborators

  • yungvenuz