Koa Router
Koa Router with support for recursive nesting and regexp and dynamic urls. No dependecies and lightweight code.
Install
npm install cca-koa-router --save
Simple Example
const Koa = router = const app = port = 3000 app app
Documentation
router(options, builder)
~ Options:
prefix
Prefix for the pathsend
If trailing paths sould be countedcase
Case sentitive
Default
prefix: '' end: false case: false
Modes:
router(builder)
No options specified, use defaultrouter('string', builder)
String will be taken as the prefixrouter({}, builder)
Specify custom options
Example
// 1app // 2app // 3app
Nesting
You can nest recursively routers
. Each can have its own options
.
Example
app /*GET / => 'Root'GET /user/view => 'View User'GET /user/edit => 'Edit User'*/
Methods
Supported methods:
GET
POST
PUT
PATCH
DELETE
Special "methods":
ALL
Used if none other method is definedNEST
Used to nest layers of the router
Example
app
Params
The router
suppors parametrs in the url/path. Parameters will be stored in the ctx.request.params
object
Example
app /*GET /user/foo/123/view/active=> {"user":"foo","id":"123","type":"active"}*/