simple-mock-api
项目中有一个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.
|
|
In config.js
config you mock api
|
|
You can custom handle the request by define your custom “hookfunc”, like this:
|
|
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
|
|
Now if you go to http://localhost:3000/get_match_detail, you’ll get
|
|
and the homescore’s value changed every time when you go to the same link.