美文网首页
json-server提供假数据接口

json-server提供假数据接口

作者: 疯狂的蜗牛Dianna | 来源:发表于2019-09-26 18:10 被阅读0次

1.json-server 作用: 根据指定的JSON文件,提供假数据接口

2.使用步骤

1.全局安装 json-server :npm i -g json-server
2.准备一个json数据
3.执行 : json-server data.json 01.png
02.png
打开http://localhost:3000/list](http://localhost:3000/list页面 json数据为
03.png
data.json的代码为:
{
    "list": [{
            "id": 1,
            "name": "张三",
            "age": 10
        },
        {
            "id": 2,
            "name": "李四",
            "age": 20
        },
        {
            "id": 3,
            "name": "王五",
            "age": 30
        }
    ]
}

REST API 格式

1. 查看 GET
2.添加 POST
3.删除 DELETE
4.更新 PUT/PATCH(打补丁)

1.查看全部 http://localhost:3000/list

2.查看具体的 http://localhost:3000/list/2

3.添加 http://localhost:3000/list

POST {name, age}

4.删除(DELETE) http://localhost:3000/list/3

5.更新(PUT) http://localhost: 3000/list/3

相关文章

网友评论

      本文标题:json-server提供假数据接口

      本文链接:https://www.haomeiwen.com/subject/kejnuctx.html