next
直到finish
npm -v
npm install -g json-server
{
"users": [
{
"id": 1,
"name": "Stark",
"age": "33"
},
{
"id": 2,
"name": "Happy",
"age": "35"
},
{
"id": 3,
"name": "Pepper",
"age": "28"
}
],
"toDo": [
{
"id": 1,
"content": "把冰箱發霉的檸檬拿去丟",
"isDone": true
},
{
"id": 2,
"content": "打電話叫媽媽匯款給我",
"isDone": false
},
{
"id": 3,
"content": "整理電腦資料夾",
"isDone": true
},
{
"id": 4,
"content": "繳電費水費瓦斯費",
"isDone": false
},
{
"id": 5,
"content": "推廣六角",
"isDone": true
}
]
}
json-server --watch db.json
json-server --watch db.json --port 3004
推薦可以使用Postman做API測試
http://localhost:3000/users
http://localhost:3000/users/2
http://localhost:3000/users?name=Happy
http://localhost:3000/users?name_like=a
http://localhost:3000/users/5
http://localhost:3000/users
{
"id": 4,
"name": "Peter",
"age": "30"
}
與POST方式相似,會將新資料完全取代舊資料,沒寫到的屬性會被刪除
http://localhost:3000/users/4
與PUT方式相似,僅更新有變動的部分,其餘資料不會變
http://localhost:3000/users/4