简介
json-server: 接口数据mock好帮手
新建文件<db.json>, 内容如下:
| 1 | { | 
- 安装&启动 - npm install -g json-server
- 默认启动在localhost:3000端口,参数: 可以监听文件变化 –watch, 可以指定端口号 –port, 可以指定host –host 
- json-server --watch db.json --port 8111 --host 127.0.0.1
- 然后会以JSON成员为键名,生成若干个请求地址,http://127.0.0.1:8111/JSON_KEY 
 
- 请求方法(实现CURD) with REST Client(Ext) -> 直达官网 - Create - 1 
 2
 3
 4
 5
 6
 7
 8
 9- ### 
 POST http://127.0.0.1:8111/users
 content-type: application/json
 
 {
 "name": "rexhang",
 "guid": "{{$guid}}",
 "time": "{{$datetime rfc1123|iso8601}}"
 }
- Update - 1 
 2
 3
 4
 5
 6
 7- ### 
 PATCH http://127.0.0.1:8111/users/1
 content-type: application/json
 
 {
 "name": "rexhang"
 }
- Read - 1 
 2- ### 
 GET http://127.0.0.1:8111/profile- 1 
 2
 3
 4- ### 
 GET http://127.0.0.1:8111/users
 ?id=1
 &name=rexhang
- Delete - 1 
 2- ### 
 DELETE http://127.0.0.1:8111/users/1
 
 
         
              