JSON Server

導入

yarn global add json-server

使い方

モックデータの作成

mock.json

{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

モックサーバーの起動

json-server --watch mock.json

curl localhost:3000/posts
curl localhost:3000/posts/1

カスタムルート

ルートの設定

先頭は必ず/はじまりにする。

route.jsons

{
	"/hoge/fuga/:id": "/articles/:id"
}

モックサーバーの起動

json-server --watch mock.json --routes routes.json

curl localhost:3000/hoge/fuga/
curl localhost:3000//hoge/fuga/1