koa2-restful
A restful koa2 api stater
Reference
https://www.jianshu.com/p/c37a13506753
or ./info.txt
for backup
Test
npm test
Run
test for dev
npm run start:dev
for prod
npm start
Mock Db
CREATE TABLE `rest`.`user` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `username_UNIQUE` (`username` ASC));
To do
- auto routing with version
- nested routing
- sample method for all http method
- sample unit test of each method
- sample data model of mysql/mongo using ORM/ODM or further encapsulated lib
- sample unit test of model
- add oauth2 with redis ttl for token/refresh token
- auto gen api doc with interactive test(swagger? apidoc?)
- body parser, logger
- add sault and encrypt for password like sensitive information (bcrypt?)
- limit access rate of same IP
- CORS
- cmd installer like yeoman
- all requirements of
./info.txt
- Use
Accept-Language
andContent-Language
header for deciding what language of contents get method return - handle file upload
- setup
pm2.config.json
for pm2 - a stub db
- set compression for large text contents ...
Naming
- use Snake case for folder and http method for filename.
- use
_${folder_name}.spec.js
for unit test __${variable_name}
for global variable ...
Notes
For each method, export an array of koa middleware. If body parser is needed, append koaBody()
before the middleware, ref: ./app/v0/demo/get.js
.