使用 json-server
搭建开发 REST API 环境
安装
npm install -g json-server
使用
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
json-server --watch db.json
$ curl http://localhost:3000/posts/1
{ "id": 1, "title": "json-server", "author": "typicode" }
其他方法如 Post、Put、Delete 也支持。