https://github.com/oxoyo/x-restful-api-generator-koa
一个基于 Koa 的 RESTful API 服务脚手架。 A RESTful API generator for Koa
https://github.com/oxoyo/x-restful-api-generator-koa
jsonwebtoken jwt koa koa-api koa-generator koa-jwt koa-multer koa-mysql koa-restful koa2-demo koa2-generator koa2-starter restful restful-api
Last synced: 10 months ago
JSON representation
一个基于 Koa 的 RESTful API 服务脚手架。 A RESTful API generator for Koa
- Host: GitHub
- URL: https://github.com/oxoyo/x-restful-api-generator-koa
- Owner: OXOYO
- License: mit
- Created: 2017-10-23T09:34:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-07T09:44:17.000Z (about 8 years ago)
- Last Synced: 2025-04-13T11:48:55.578Z (about 1 year ago)
- Topics: jsonwebtoken, jwt, koa, koa-api, koa-generator, koa-jwt, koa-multer, koa-mysql, koa-restful, koa2-demo, koa2-generator, koa2-starter, restful, restful-api
- Language: JavaScript
- Homepage:
- Size: 145 KB
- Stars: 18
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# X-RESTful-API-Generator-Koa
A RESTful API service generator by Koa.
[ ](https://travis-ci.org/OXOYO/X-RESTful-API-Generator-Koa)
[](https://codecov.io/github/OXOYO/X-RESTful-API-Generator-Koa?branch=master)
[](https://nodejs.org/)
[]()
[](https://david-dm.org/OXOYO/X-RESTful-API-Generator-Koa)
[](https://codebeat.co/projects/github-com-oxoyo-x-restful-api-generator-koa-master)
[]()
[](https://gitter.im/X-RESTful-API-Generator-Koa/chat)
English | [简体中文](./README_CN.md)
## Start
```bash
# clone
git clone
# install dependencies
npm i
# import the src/x-restful-api-generator-koa.sql into the database.
# start serve with hot reload
npm run dev
```
Node.js >= 7.6.0 required.
## Develop Step
1.Edit config.js
2.Export the database to schema by [sequelize-auto](https://github.com/sequelize/sequelize-auto)
```bash
npm -g install mysql
sequelize-auto -o "./src/schema" -d x-restful-api-generator-koa -h localhost -u root -p 3306 -e mysql
```
3.Create module directories and files
```bash
apps
\_ newModules
Ctrl.js
Model.js
Routers.js
```
## Build
```bash
npm run build
```
## production
```bash
pm2 start ecosystem.config.js --name x-restful-api-generator-koa --env production
```
## Demo
To run the demo, you need to import the `./src/x-restful-api-generator-koa.sql` into Mysql
### demoModule_001
URL: http://localhost:3000/x-restful-api-generator-koa/demoModule_001/login
Resonse:
```bash
{
"code": 200,
"msg": "登录成功!",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyTmFtZSI6InRlc3QiLCJwYXNzd29yZCI6IjEyMzQ1NiIsImlhdCI6MTUwODkyMTY2OSwiZXhwIjoxNTA5MDA4MDY5fQ.2occtME3kLUDxntJXOz5e1dkspybGIVqbDPRgaE6lZA"
}
}
```
URL: http://localhost:3000/x-restful-api-generator-koa/demoModule_001/list
Response:
```bash
{
"code": 200,
"msg": "查询列表成功!",
"data": {
"count": 300,
"list": []
}
}
```
URL: http://localhost:3000/x-restful-api-generator-koa/demoModule_001/verify/list
Response:
```bash
{
"code": 9999,
"msg": "token无效!请重新登录!",
"data": {}
}
```
### Articles
URL: http://localhost:3000/x-restful-api-generator-koa/articles/add
Request Body:
```bash
{
title: 'myArticle_001'
content: 'yyyyyyyyyyyyyyyyyyyyyyy'
}
```
Response:
```bash
{
"code": 200,
"msg": "添加文章成功!",
"data": {
"id": 3,
"title": "myArticle_001",
"content": "yyyyyyyyyyyyyyyyyyyyyyy",
"updatedAt": "2017-10-27T07:52:21.745Z",
"createdAt": "2017-10-27T07:52:21.745Z"
}
}
```
URL: http://localhost:3000/x-restful-api-generator-koa/articles/update
Request Body:
```bash
{
id: '3'
content: 'xxxxxx'
}
```
Response:
```bash
{
"code": 200,
"msg": "编辑文章成功!",
"data": {
"id": 3,
"title": "myArticle_003",
"content": "xxxxxx",
"createdAt": "2017-10-26T23:52:21.000Z",
"updatedAt": "2017-10-27T00:08:55.000Z"
}
}
```
URL: http://localhost:3000/x-restful-api-generator-koa/articles/remove
Request Body:
```bash
{
id: '2'
}
```
Response:
```bash
{
"code": 200,
"msg": "删除文章成功!",
"data": 1
}
```
URL: http://localhost:3000/x-restful-api-generator-koa/articles/list?pageSize=1¤tPage=1
Response:
```bash
{
"code": 200,
"msg": "查询账号列表成功!",
"data": {
"count": 2,
"list": [
{
"id": 1,
"title": "myArticle_001",
"content": "yyyyyyyyyyyyyyyyyyyyyyy",
"createdAt": "2017-10-26T23:46:10.000Z",
"updatedAt": "2017-10-26T23:46:10.000Z"
}
]
}
}
```
### File Upload
URL: http://localhost:63342/X-RESTful-API-Generator-Koa/src/apps/Files/upload.html
Response:
```bash
{
"status": 200,
"msg": "上传成功!",
"data": {
"file": {
"fieldname": "file",
"originalname": "app.png",
"encoding": "7bit",
"mimetype": "image/png",
"destination": "E:\\Webstorm_WorkSpace\\X-RESTful-API-Generator-Koa\\assets\\uploads",
"filename": "1510817484098.png",
"path": "E:\\Webstorm_WorkSpace\\X-RESTful-API-Generator-Koa\\assets\\uploads\\1510817484098.png",
"size": 958
},
"filename": "1510817484098.png",
"url": "//localhost:3000/assets/uploads/1510817484098.png"
}
}
```
## TODO
```bash
1.error handler middleware
```
## License
[MIT](http://opensource.org/licenses/MIT)