JSON Server
JSON Server可以讓我們在本地端快速建立具有CRUD的REST API供測試使用 安裝 npm install -g json-server 首先先建立一個json檔用來存放你的資料 JSON資料庫必須要以物件為開始 {"posts": []} 下面就是建立了posts這個資料表 裡面有三筆資料 db.json { "posts" : [ { "id" : 1 , "title" : "json-server" , "author" : "typicode" }, { "id" : 2 , "title" : "json" , "author" : "this is second" }, { "id" : 3 , "title" : "xml" , "author" : "this is third" } ] } 接著輸入指令會自動建立JSON資料庫 並監聽資料庫事件 json-server --watch db.json 接著開啟瀏覽器在網址輸入 http://localhost:3000/ 就會看到你剛剛所創的資料表了 http://localhost:3000/db 取得資料庫所有資料表 http://localhost:3000/posts 取得posts這個資料表 http://localhost:3000/posts/2 取得posts這個資料表id為2的單筆資料 如果要指定不同的port來顯示網頁也是可以的 json-server --watch db.json --port 4000 也可以模擬叫慢的API回應時間 json-server --delay 500 db.json JSON Server是遵循 Restful api 架構,所以可以使用GET, PO...