# 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 比较操作符清单(查询条件)
| is | Example: {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. |
| isnocase | Example: {column:{isnocase:value}} | Used to see if a column value is equal to a supplied value. Ignores case of column and value. |
| left | Example: {column:{left:value}} | Used to see if the start of a column is the same as a supplied value. |
| leftnocase | Example: {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. |
| right | Example: {column:{right:value}} | Used to see if the end of a column is the same as a supplied value. |
| rightnocase | Example: {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 |
| like | Example: {column:{like:value}} | Used to see if column contains a supplied value. |
| likenocase | Example: {column:{likenocase:value}} | Used to see if column contains a supplied value. Ignores case of column and value |
| regex | Example: {column:{regex:value}} | Used to see if column matches a supplied regular expression. |
| lt | Example: {column:{lt:value}} or {column:{'<':value}} | Used to see if column is less than a supplied value. |
| lte | Example: {column:{lte:value}} or {column:{'<=':value}} | Used to see if column is less than or equal to a supplied value. |
| gt | Example: {column:{gt:value}} or {column:{'>':value}} | Used to see if column is greater than a supplied value. |
| gte | Example: {column:{gte:value}} or {column:{'>=':value}} | Used to see if column is greater than or equal to a supplied value. |
| has | Example: {column:{has:value}} | Used to see if column that is an object has a value or object appearing in its tree. |
| hasAll | Example: {column:{hasAll:value}} | Used to see if column that is an object has a value or object appearing in its tree. |
| isSameArray | Example: {column:{isSameArray:value}} | Used to see if column is an array and is the same as a supplied array. |
| isSameObject | Example: {column:{isSameObject:value}} | Used to see if column is an object and is the same as a supplied object. |
| isString | Example: {column:{isString:true}} | Used to see if column a string. |
| isNumber | Example: {column:{isNumber:true}} | Used to see if column a number. |
| isArray | Example: {column:{isArray:true}} | Used to see if column an array. |
| isObject | Example: {column:{isObject:true}} | Used to see if column an object. |
| isFunction | Example: {column:{isFunction:true}} | Used to see if column a function. |
| isBoolean | Example: {column:{isBoolean:true}} | Used to see if column a boolean (true/false). |
| isNull | Example: {column:{isNull:true}} | Used to see if column null. |
| isUndefined | Example: {column:{isUndefined:true}} | Used to see if column undefined. |