一个用于快速搭建RESTful API的接口 JSONPlaceholder 地址
Json-Server ,个人搭建一个 访问GITHub
你可以创建一个文件夹,执行npm install -g json-server
本地实例化一个项目npm install json-server --save
我们的package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14 "name": "jsonserver",
"version": "1.0.0",
"description": "test restful api",
"main": "index.js",
"scripts": {
"json:server": "json-server --watch db.json",
"json:server:remote": "json-server http://jsonplaceholder.typicode.com/db"
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.12.2"
}
}
此时你创建一个db.json文件,然后输入对应的json1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20{
"users": [
{
"name": "Henry",
"phone": "333-444-555",
"id": 1
},
{
"name": "adfasdf",
"phone": "fasdfasfd",
"email": "asdfasfd",
"id": 3
}
],
"xxx": [
{
"aa":“abab”
}
]
}
运行npm run json:server ,会执行对应的db.json 数据,给你
在浏览器可以直接访问,会获取对应的接口数据
你们可以使用postman去测试调用,各种方法的使用具体看官网
1 | // 获取所有用户信息 |