一、json-server工具的使用
可以快速的搭建符合RESTful API服务。返回符合RESTful规范的数据;
1、全局引入json-server包
npm install -g json-server
2、创建json格式的db.json文件
{
"jsonData": [
{
"name": "小明"
}
]
}
3、在json文件所在的根目录执行代码
json-server --watch db.json
- 启动成功显示如下内容
Index:
http://localhost:3000/
Static files:
Serving ./public directory if it exists
Endpoints:
http://localhost:3000/jsonData
- 访问接口返回的数据,没有id会默认给加上id
[
{
"name": "小明",
"id": "81fd"
}
]