博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Koa RESTful 脚手架分享
阅读量:5780 次
发布时间:2019-06-18

本文共 2332 字,大约阅读时间需要 7 分钟。

X-RESTful-API-Generator-Koa

A RESTful API generator for Koa.

Start

git clone  npm i  npm run dev

Demo

demoModule_001

URL: :3000/x-restful-api-generator-koa/demoModule_001/login

Resonse:

{    "code": 200,    "msg": "登录成功!",    "data": {      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyTmFtZSI6InRlc3QiLCJwYXNzd29yZCI6IjEyMzQ1NiIsImlhdCI6MTUwODkyMTY2OSwiZXhwIjoxNTA5MDA4MDY5fQ.2occtME3kLUDxntJXOz5e1dkspybGIVqbDPRgaE6lZA"    }  }

URL: :3000/x-restful-api-generator-koa/demoModule_001/list

Response:

{    "code": 200,    "msg": "查询列表成功!",    "data": {      "count": 300,      "list": []    }  }

URL: :3000/x-restful-api-generator-koa/demoModule_001/verify/list

Response:

{    "code": 9999,    "msg": "token无效!请重新登录!",    "data": {}  }

Articles

URL: :3000/x-restful-api-generator-koa/articles/add

Request Body:

{    title: 'myArticle_001'    content: 'yyyyyyyyyyyyyyyyyyyyyyy'  }

Response:

{    "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: :3000/x-restful-api-generator-koa/articles/update

Request Body:

{    id: '3'    content: 'xxxxxx'  }

Response:

{    "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: :3000/x-restful-api-generator-koa/articles/remove

Request Body:

{    id: '2'  }

Response:

{    "code": 200,    "msg": "删除文章成功!",    "data": 1  }

URL: :3000/x-restful-api-generator-koa/articles/list?pageSize=1&currentPage=1

Response:

{    "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"        }      ]    }  }

Develop

1.Edit config.js

2.Export the database to schema by

sequelize-auto -o "./src/schema" -d x-restful-api-generator-koa -h localhost -u root -p 3306 -e mysql

3.Create Modules

apps    \_ newModules        Ctrl.js        Model.js        Routers.js

TODO

1.error handler middleware  2.file upload demo

转载地址:http://yxuyx.baihongyu.com/

你可能感兴趣的文章
实用工具
查看>>
zabbix 服务端安装
查看>>
我的友情链接
查看>>
JavaScript学习笔记(前言)
查看>>
android 腾讯微博分享功能实现及自定义webview认证
查看>>
SparkSQL JDBC和JDBCServer区别
查看>>
我的友情链接
查看>>
详解区块链中EOS的作用。
查看>>
我的友情链接
查看>>
mysql-error 1236
查看>>
sshd_config设置参数笔记
查看>>
循序渐进Docker(一)docker简介、安装及docker image管理
查看>>
jsp页面修改后浏览器中不生效
查看>>
大恶人吉日嘎拉之走火入魔闭门造车之.NET疯狂架构经验分享系列之(四)高效的后台权限判断处理...
查看>>
Oracle HRMS,PeopleSoft HR,SAP HR区别
查看>>
信号量实现进程同步
查看>>
Spring4-自动装配Beans-通过构造函数参数的数据类型按属性自动装配Bean
查看>>
iPhone图标
查看>>
hdu 3308 LCIS
查看>>
hdu 1231 最大连续子序列
查看>>