安裝
shell> npm install -g json-server
db.json
{
"posts": [{
"id": 1,
"title": "json-server",
"author": "typicode"
}],
"comments": [{
"id": 1,
"body": "some comment",
"postId": 1
}],
"profile": {
"name": "typicode"
}
}
Start JSON Server
shell> json-server --watch db.json
shell> json-server --watch db.json --port 3004
shell> json-server http://example.com/file.json
shell> json-server http://jsonplaceholder.typicode.com/db
http://localhost:3000/posts/1
{ "id": 1, "title": "json-server", "author": "typicode" }