1、安装JSON Server
sudo npm install -g json-server
2、创建json文件 如:db.json
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
3、启动 JSON Server
npx json-server db.json
访问 http://localhost:3000/posts/1, 可以得到
{ "id": 1, "title": "json-server", "author": "typicode" }