1️⃣ 使用json-server搭建REST API
2️⃣ json-server是什么?使用json-server
在线文档: https://github.com/typicode/json-server
下载: npm install -g json-server
目标根目录下创建数据库json文件: db.json
{"posts": [{ "id": 1, "title": "json-server1", "author": "typicode1" }{ "id": 2, "title": "json-server2", "author": "typicode2" }{ "id": 3, "title": "json-server3", "author": "typicode3" }],"comments": [{ "id": 1, "body": "some comment1", "postId": 1 }{ "id": 2, "body": "some comment2", "postId": 2 }{ "id": 3, "body": "some comment3", "postId": 3 }],"profile": { "name": "typicode" }}
启动服务器执行命令: json-server —watch db.json
2️⃣ 使用浏览器访问测试
http://localhost:3000/posts
http://localhost:3000/posts/1
2️⃣ 使用postman测试接口
测试GET/POST/PUT/DELETE请求
