2.0.1 • Published 7 years ago
koa-rest-controller v2.0.1
koa-rest-controller 
koa-rest-controller is a super simple tool to build Koa.js controller like Laravel controller
Requirement
- node.js >= 8
Install
yarn add koa-rest-controllerUsage
Basically, you can assign an object to get koa-router routes
const rest = require('koa-rest-controller')
const controller = {
index (ctx) {
},
store (ctx) {
},
// ...
}
rest(
{
resource: 'foo',
controller
}
)Or, you can assign nested resource like this
rest(
{
resource: ['foo', 'bar'],
controller
}
)The path looks like this /foo/:fooId/bar/:id
| key | description | type | |
|---|---|---|---|
| resource | Route resources, it should be an array or a string. | string or array | |
| controller | An object to define CRUD like Laravel project. | object | |
| routeMiddleware | An object to define CRUD middleware like Laravel project. | object | |
| prefix | Add prefix to all routes | string | |
| middleware | Add koa middleware to all routes | function |