From 539599f14e11a5c140789d576742cfc99461794a Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 6 Feb 2024 22:02:53 +0800 Subject: [PATCH] update json-server --- json-server/README.md | 36 +++++++++++++++++++++++++------- json-server/data/db.json | 26 ++++++++++++++++++++--- json-server/data/public/.gitkeep | 0 json-server/docker-compose.yml | 2 +- 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 json-server/data/public/.gitkeep diff --git a/json-server/README.md b/json-server/README.md index 720b73c..0cc0436 100644 --- a/json-server/README.md +++ b/json-server/README.md @@ -12,7 +12,7 @@ version: "3.8" services: json-server: image: vimagick/json-server - command: -H 0.0.0.0 -p 3000 -w db.json + command: -h 0.0.0.0 -p 3000 -s ./public db.json init: true ports: - "3000:3000" @@ -28,12 +28,32 @@ services: ```json { "posts": [ - { "id": 1, "title": "json-server", "author": "typicode" } + { + "id": "1", + "title": "a title", + "views": 100 + }, + { + "id": "2", + "title": "another title", + "views": 200 + } ], "comments": [ - { "id": 1, "body": "some comment", "postId": 1 } + { + "id": "1", + "text": "a comment about post 1", + "postId": "1" + }, + { + "id": "2", + "text": "another comment about post 1", + "postId": "1" + } ], - "profile": { "name": "typicode" } + "profile": { + "name": "typicode" + } } ``` @@ -45,10 +65,10 @@ docker-compose up -d pip install httpie http GET :3000/posts -http POST :3000/posts id:=2 title=hello author=world -http PUT :3000/posts/2 title=Hello author=World -http PATCH :3000/posts/2 title=HELLO -http DELETE :3000/posts/2 +http POST :3000/posts id:=3 title=hello author=world +http PUT :3000/posts/3 title=Hello author=World +http PATCH :3000/posts/3 title=HELLO +http DELETE :3000/posts/3 http GET :3000/db ``` diff --git a/json-server/data/db.json b/json-server/data/db.json index 7389028..f3f508b 100644 --- a/json-server/data/db.json +++ b/json-server/data/db.json @@ -1,9 +1,29 @@ { "posts": [ - { "id": 1, "title": "json-server", "author": "typicode" } + { + "id": "1", + "title": "a title", + "views": 100 + }, + { + "id": "2", + "title": "another title", + "views": 200 + } ], "comments": [ - { "id": 1, "body": "some comment", "postId": 1 } + { + "id": "1", + "text": "a comment about post 1", + "postId": "1" + }, + { + "id": "2", + "text": "another comment about post 1", + "postId": "1" + } ], - "profile": { "name": "typicode" } + "profile": { + "name": "typicode" + } } diff --git a/json-server/data/public/.gitkeep b/json-server/data/public/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/json-server/docker-compose.yml b/json-server/docker-compose.yml index c977d23..b8775d1 100644 --- a/json-server/docker-compose.yml +++ b/json-server/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.8" services: json-server: image: vimagick/json-server - command: -H 0.0.0.0 -p 3000 -w db.json + command: -h 0.0.0.0 -p 3000 -s ./public db.json init: true ports: - "3000:3000"