# api-service **Repository Path**: lixl0632/api-service ## Basic Information - **Project Name**: api-service - **Description**: tiny api service - **Primary Language**: NodeJS - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-02-05 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # api-service #### Description 基于express 及 jwt 的超轻量级 api服务,数据库采用js taffy,通过node-localstorage将数据持久化保证再次启动时数据还在。 与mockjs不同的是,这个系统模拟的是真实前后端数据交互,支持增删改查,数据动态变化,而非mockjs的数据挡板模式(静态预设数据)。 与moco不同的是,api接口是动态的,每个api对应一个数据单元(table),api接口不需要预配置,table也不需要预创建,都是动态的,数据也是动态的,完全是一套微内核的动态后台系统。 针对那些需要快速出效果进行功能验证的项目来说,此工具提供了动态数据交互的支撑能力。 ##### QQ: 16935696 #### Software Architecture Software architecture description #### Installation 1. 下载源码 2. 在源码目录下执行 yarn install 或者 npm install 安装依赖包 3. 通过npm start 启动, 默认的侦听端口是3000 #### Instructions 本系统提供的基本接口能力如下: #### 1. 获取单条数据: method:get url: '/api/:table/:id' //table 数据单元名称,类似于表名; id 数据主键值,注:taffy数据库默认主键名称为:'___id' 返回: 返回json对象格式的数据 #### 2. 获取列表数据: method:get 或者 post url: '/api/:table' //table 数据单元名称,类似于表名; 参数: size : 可选,默认30,获取多少条数据 page : 可选,默认0,起始记录,并非按照size进行分页获取,而是实际的记录位置,比如 此值为20,则是从第20条记录开始,后续会改成页数 conditions : 可选,筛选条件,筛选条件的规则采用taffy的查询条件规则,详细参考[http://taffydb.com/writing_queries.html](http://http://taffydb.com/writing_queries.html) 查询示例: 数据格式:[{"skus":[{"tt":{"aa":{"bb":1}}}]}] 查询条件:{'skus':{'has':{'tt': { 'has':{'aa': {'has':{'bb':{'gt': 0}}}}}}}} 或者:{'skus':{'has':{'tt': { 'has':{'aa':{'bb':1}}}}}} 数组元素子元素查询要用has,子元素属性条件如果不是具体值而是比较类的运算符标识时,也需要用has包裹条件,当一个属性有多个筛选条件时(or关系),则将所有的条件封装在一个数组中,如:{status:['0',{isNull:true},{isUndefined :true}]}; 对于get,参数通过queryString的方式传递; 对于post方法,参数通过json对象传递 返回: 返回json数组格式的数据 ##### taffy 比较操作符清单(查询条件)
isExample:
{column:{is:value}}
Used to see if a column is of same type and value of supplied value.
==Example:
{column:{'==':value}}
Used to see if a column matches a supplied value using JavaScript's liberal coercion rules.
===Example:
{column:{'===':value}}
Used to see if a column is of same type and value of supplied value.
isnocaseExample:
{column:{isnocase:value}}
Used to see if a column value is equal to a supplied value. Ignores case of column and value.
leftExample:
{column:{left:value}}
Used to see if the start of a column is the same as a supplied value.
leftnocaseExample:
{column:{leftnocase:value}}
Used to see if the start of a column is the same as a supplied value. Ignores case of column and value.
rightExample:
{column:{right:value}}
Used to see if the end of a column is the same as a supplied value.
rightnocaseExample:
{column:{rightnocase:value}}
Used to see if the end of a column is the same as a supplied value. Ignores case of column and value
likeExample:
{column:{like:value}}
Used to see if column contains a supplied value.
likenocaseExample:
{column:{likenocase:value}}
Used to see if column contains a supplied value. Ignores case of column and value
regexExample:
{column:{regex:value}}
Used to see if column matches a supplied regular expression.
ltExample:
{column:{lt:value}} or {column:{'<':value}}
Used to see if column is less than a supplied value.
lteExample:
{column:{lte:value}} or {column:{'<=':value}}
Used to see if column is less than or equal to a supplied value.
gtExample:
{column:{gt:value}} or {column:{'>':value}}
Used to see if column is greater than a supplied value.
gteExample:
{column:{gte:value}} or {column:{'>=':value}}
Used to see if column is greater than or equal to a supplied value.
hasExample:
{column:{has:value}}
Used to see if column that is an object has a value or object appearing in its tree.
hasAllExample:
{column:{hasAll:value}}
Used to see if column that is an object has a value or object appearing in its tree.
isSameArrayExample:
{column:{isSameArray:value}}
Used to see if column is an array and is the same as a supplied array.
isSameObjectExample:
{column:{isSameObject:value}}
Used to see if column is an object and is the same as a supplied object.
isStringExample:
{column:{isString:true}}
Used to see if column a string.
isNumberExample:
{column:{isNumber:true}}
Used to see if column a number.
isArrayExample:
{column:{isArray:true}}
Used to see if column an array.
isObjectExample:
{column:{isObject:true}}
Used to see if column an object.
isFunctionExample:
{column:{isFunction:true}}
Used to see if column a function.
isBooleanExample:
{column:{isBoolean:true}}
Used to see if column a boolean (true/false).
isNullExample:
{column:{isNull:true}}
Used to see if column null.
isUndefinedExample:
{column:{isUndefined:true}}
Used to see if column undefined.
#### 3. 更新单条数据: method:put url: '/api/:table/:id' //table 数据单元名称,类似于表名; id 数据主键值,注:taffy数据库默认主键名称为:'___id' 参数: data: 必须,需要更新的json对象格式的数据 返回: 返回更新后的json对象数据 #### 4. 新增数据: method:post url: '/api/:table/save' //table 数据单元名称,类似于表名;save是固定标识 参数: list: 必须,需要新增的json数组格式的数据 返回: 返回更新后的list数据 #### 5. 更新多条数据: method:post url: '/api/:table/update' //table 数据单元名称,类似于表名; update是固定标识 参数: list: 必须,需要新增/更新的json数组格式的数据,如果数据(根记录)包含主键(名称为:'___id')值,则执行更新,如果不包含主键,则执行插入。 返回: 返回更新后的list数据; #### 6. 合并数据: method:post url: '/api/:table/merge/:key' //table 数据单元名称,类似于表名; merge是固定标识; key主键字段名称,注:taffy数据库默认主键名称为:'___id' 参数: list: 必须,需要新增/更新的json数组格式的数据,如果数据(根记录)包含主键(名称为:'___id')值,则执行更新,如果不包含主键,则执行插入。 #### 7. 删除数据 1: method:delete url: '/api/:table/:ids' //table 数据单元名称,类似于表名; ids是主键值序列(由逗号链接的主键值串,连接后通过url编码的方式将逗号转化) 参数: list: 必须,需要新增/更新的json数组格式的数据,如果数据(根记录)包含主键(名称为:'___id')值,则执行更新,如果不包含主键,则执行插入。 #### 8. 删除数据 2: method:post url: '/api/:table/delete' //table 数据单元名称,类似于表名; delete是固定标识 参数: ids: 必须,id值组成的数组。 #### 9. 图片加载: method:get url: '/api/:table/image/:file' //table 数据单元名称,类似于表名; image是固定标识; file图片文件名称 #### 10. 自定义json数据格式api: method:get 或 post 不限制method url: '/(:path/)*:file' //path 目录名,支持多级; file json文件名称(不包括扩展名),文件扩展名必须是json #### Contribution 1. Fork the repository 2. Create Feat_xxx branch 3. Commit your code 4. Create Pull Request #### Gitee Feature 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md 2. Gitee blog [blog.gitee.com](https://blog.gitee.com) 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)