内容へ移動
猫型iPS細胞研究所
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
現在位置:
INDEX
»
node.js
»
JSON Server
トレース:
node.js:jsonserver
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== JSON Server ====== [[https://github.com/typicode/json-server/blob/master/README.md#getting-started|JSON Server]] モック用のAPIサーバーが簡単に作成できる。 ===== Getting started ===== ==== 1.ディレクトリ作成 ==== <code bash> $ mkdir jsonsever $ cd jsonserver </code> ==== 2.グローバルインストール ==== もしグローバルインストールでなければnode_modules/.bin/ にあるモジュールを実行する...面倒です。 <code bash> $ npm install -g json-server </code> ==== 3.レスポンス元となるjsonファイル作成 ==== <code bash /jsonserver/db.json> { "users": [ { "id": 1, "name": "safa"}, { "id": 2, "name": "hana"} ] } </code> ==== 4.routeファイル作成 ==== <code bash /jsonserver/routes.json> { "/users/:id": "/users/?id=:id" } </code> ==== 5.json-serverを実行する ==== <code> >json-server --watch db.json --routes routes.json \{^_^}/ hi! Loading db.json Loading routes.json Done Resources http://localhost:3000/users Other routes /users/:id -> /users/?id=:id Home http://localhost:3000 Type s + enter at any time to create a snapshot of the database Watching... </code> === 6.アクセス === <code> // http://localhost:3000 // スタートアップ画面 Congrats! You're successfully running JSON Server ✧*。٩(ˊᗜˋ*)و✧*。 </code> <code> // http://localhost:3000/users [ { "id": 1, "name": "safa" }, { "id": 2, "name": "hana" } ] </code> <code> // http://localhost:3000/users/2 // routesで設定しているので /users/?id=2 となる { "/users/:id": "/users/?id=:id" } </code>
node.js/jsonserver.txt
· 最終更新: 2019/12/31 08:07 by
ips
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ