ift
InterFace Toolkit 接口工具集
by 鬼道(luics)
安装
tnpm install -g ift
MAC 用户请使用sudo tnpm install -g ift
1. 初始化
请使用
ift -h
查看所有命令
请在项目根目录下运行
ift -i
or
ift --init
会影响的文件结构为
demo/
--data/
----demo.js
----if-config.json
doc/
数据文件
ift -i
生成的 demo.js 是一个 IF 数据文件,即可以作为调试数据使用(ift -e
),又能生成接口文档(ift -s
)。
下面显示了重要的配置信息:
exportsconfig = "name": "这是接口名" "desc": "这是接口的详细描述" // 线上地址 "url": "http://example.com/demo" // 日常地址 "urlDaily": "http://daily.example.net/demo" // 预发地址 "urlPrepub": "http://example.com/demo" // 支持的 Method 集合 "method": 'GET' 'POST' // 响应与模板的映射关系 "template": "response": "tpl1.php" "responseError": "tpl2.php" ;
2. 文档同步
用于将数据文件 demo.js 生成接口文档
请在项目根目录下运行(首次运行该命令前请先运行ift --init
)
ift -s
or
ift --sync
该命令默认读取的配置文件位于 demo/data/if-config.json
,所有数据文件均位于 demo/data/
默认生成的接口文档为 doc/api.md
(查看 api.md 文档)
doc/
--api.md
if-config.json
if-config.json 是接口文档配置文件
"title": "接口文档" "extraHtml": "<h3>额外的html片段</h3>" "savePath": "../../doc/api.md" "files": "demo"
savePath
设置保存接口文档的相对路径files
指定接口文件,无需文件扩展名
3. 接口服务器
请在项目根目录下运行
ift -e -p 9999
or
ift --server --port 9999
浏览器中访问 http://localhost:9999/demo.js
,demo.js
可替换为合适的值
4. 接口校验
- 运行于 node 环境
-
调用
; -
返回
"pass": 1 // 1-校验通过 0-未通过"defined": 4 // 校验的字段数"undefined": 0 // 需要定义却未定义的字段数"mismatch": 0 // 格式不匹配的字段数"stack": // 校验堆栈,一般用不着"{root}""log": // 出错日志
-
- 运行于 browser 环境
-
调用
window; -
返回 同 node 版本
-
- HTTP API,方便集成
- UI 工具