simple-mock-api
来源:互联网 发布:网络教育专科学费 编辑:程序博客网 时间:2024/05/20 22:01
项目中有一个Activiy需要轮询多个接口,实时刷新数据。这里很多业务逻辑都需要依赖当前的状态,所以简单写了一个服务端,用于生成一些mock data,并且支持数据实时刷新。
项目地址:simple-mock-api
挂到腾讯云上就可以公网访问了。
simple-mock-api
Use json-server make this simple mock api server.
Usage
- checkout this project,and cd
- type
npm install
in terminal to install dependences - run
node app.js
- get result via your configed cgi,like http://localhost:3000/get_match_players
Config
You can config
cgi,default json file,custom handle the request, modify json response
Example
Create a get_match_detail.json
file in data
folder.
{ "state": 1, "title":"NBA", "time":"2017-01-01", "homescore": "101", "guestscore": "115"}
In config.js
config you mock api
var config = [{ "cgi":"/get_match_detail", "filepath":"data/get_match_detail.json", "need_cache":true, "hookfunc":func_get_match_detail},{ "cgi":"/get_match_players", "filepath":"data/get_match_players.json", "need_cache":false, "hookfunc":func_get_match_players},];
You can custom handle the request by define your custom “hookfunc”, like this:
var func_get_match_detail = function(defaultObj,req) { //increase homescore every time var homescore = parseInt(defaultObj.homescore)+1+""; defaultObj.homescore = homescore;}
The param defaultObj
means the parsed json object you defined in the key “filepath”.
If the key “need_cache” seted true, than your hookfunc can change the defaultObj in the cache forever.
Start JSON Server
$ node app.js
Now if you go to http://localhost:3000/get_match_detail, you’ll get
{ "state": 1, "title":"NBA", "time":"2017-01-01", "homescore": "102", "guestscore": "115"}
and the homescore’s value changed every time when you go to the same link.
0 0
- simple-mock-api
- mock-api
- Mock API
- mock-api使用
- mock-api 使用手册
- 使用SoapUI mock REST API
- 利用eolinker实现api接口mock测试(mock server)
- Simple API for XML
- My simple API
- Simple Consumer Scala API
- OpenGL API simple summary
- How to Mock Singletons in 3 Simple Ways
- 快速mock-api最简单实践案例
- Mock
- mock
- mock
- mock
- SAX:Simple API for XML
- Markdown编辑器技巧
- Android ListView
- bzoj4721 [Noip2016]蚯蚓
- 卡尔曼滤波之目标跟踪
- VS2015开发FastReport报表系列--0001
- simple-mock-api
- http请求返回网页的源代码
- linux -unrar解压缩
- ViewPager+Fragment问题
- ios 上线审核 内支付 问题
- opencv2—(1)载入、显示及保存图像
- 轻松搞定面试中的链表题目
- 正向反馈机制探讨
- 链表中倒数第k个节点