ceshu / Autoapi
Licence: mit
基于node.js的RESTful Api生成器
Stars: ✭ 254
Programming Languages
javascript
184084 projects - #8 most used programming language
AutoAPI
基于node.js的RESTful Api生成器
安装
修改配置文件
配置文件路径:config/config.js
安装依赖包
$ npm install
数据表自动生成模型
$ node generate
启动服务端
$ node app
使用方法
1.查询
对RESTful URL进行GET请求即可查询到数据库中的数据,可以通过querystring来修改参数。
查询规则:
所有不以_开头的键,都会被放进sequelize#query()的where参数中。
所有以_开头的键,都会被放进sequelize#query()的参数中,和where保持平级。
查询整个数据表中的数据:
http://"URL":"端口号"/"表名"
查询数据表中某id(主键)的数据:
http://"URL":"端口号"/"表名"/"id"
查询数据表中某字段值为"XXX"的数据:
http://"URL":"端口号"/"表名"/?"字段名"="XXX"
查询数据表中前"X"条数据:
http://"URL":"端口号"/"表名"/?_limit="X"
按照某字段(倒序)排序数据表中数据:
http://"URL":"端口号"/"表名"/?_order="字段名" DESC
按照某字段(升序)排序数据表中数据:
http://"URL":"端口号"/"表名"/?_order="字段名" ASC
跳过前"N"条后,查询数据表中数据:
http://"URL":"端口号"/"表名"/?_offset="N"
按某字段分组排序查询数据表中数据:
http://"URL":"端口号"/"表名"/?_group="字段名"
查询某字段中含有"Str"的数据:
const res = qs.stringify({"字段名": {$like: '%Str%'}})
http://"URL":"端口号"/"表名"/?res
查询某字段中大于"M"并小于"N"的数据:
const res = qs.stringify({"字段名": {$gt: "M",$lt: "N"}})
http://"URL":"端口号"/"表名"/?res
更多规则请参考Sequelize文档。
2.增、删、改
增、删、改的规则与查询类似,分别对URL进行POST、DELETE、PUT请求即可。
3.权限控制
AutoAPI集成了koa-jwt模块,使用JWT来控制权限,签发token:
node token
也可以通过Koa中间件控制权限。
如果你喜欢AutoAPI,可以点击右上角的 star
,想实时关注进度,可以点击右上角的 watch
。
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].