https://github.com/michael34435/koa-rest-controller
https://github.com/michael34435/koa-rest-controller
controller koa koajs router
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/michael34435/koa-rest-controller
- Owner: michael34435
- License: mit
- Created: 2018-06-26T06:09:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-20T10:34:55.000Z (over 7 years ago)
- Last Synced: 2025-08-24T12:56:11.590Z (10 months ago)
- Topics: controller, koa, koajs, router
- Language: JavaScript
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
koa-rest-controller 
---
`koa-rest-controller` is a super simple tool to build `Koa.js` controller like `Laravel` controller
## Requirement
* node.js >= 8
## Install
```bash
yarn add koa-rest-controller
```
## Usage
Basically, you can assign an object to get koa-router routes
```js
const rest = require('koa-rest-controller')
const controller = {
index (ctx) {
},
store (ctx) {
},
// ...
}
rest(
{
resource: 'foo',
controller
}
)
```
Or, you can assign nested resource like this
```js
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||