https://github.com/lpreterite/koa-sequelize-rest
Quickly add koa restful api
https://github.com/lpreterite/koa-sequelize-rest
Last synced: 3 months ago
JSON representation
Quickly add koa restful api
- Host: GitHub
- URL: https://github.com/lpreterite/koa-sequelize-rest
- Owner: lpreterite
- License: mit
- Created: 2017-03-14T07:18:58.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-15T10:04:55.000Z (about 8 years ago)
- Last Synced: 2024-04-26T02:04:12.916Z (about 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-sequelize-rest
Quickly add koa restful api# Installation
```
npm install koa-sequelize-restful --save
```# Example
```
const Koa = require('koa');
const app = new Koa();const restful = require('koa-sequelize-restful');
const router = restful(new Router({prefix: '/users'}), { model: user });app.use(router.routes());
app.use(router.allowedMethods());```
# Document
## restful(router, options, hooks)### options
```
{
model: user //
paginate: {
default: 0,
max: 20
},
idField: 'id'
}
```### hooks
```
{
before: {
all: [], //add in before with all hooks
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [], //add in after with all hooks
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
}
```#### hooks life cycle
```
{
before: {
all: [call_1], //add in before with all hooks
find: [call_11],
get: [call_12],
create: [call_13],
update: [call_14],
patch: [call_15],
remove: [call_16]
},
after: {
all: [call_2], //add in after with all hooks
find: [call_21],
get: [call_22],
create: [call_23],
update: [call_24],
patch: [call_25],
remove: [call_26]
}
}
```**The order of execution**
- find
- call_1
- call_11
- find
- call_21
- call_2# License
Copyright (c) 2017
Licensed under the [MIT license](LICENSE).