|
1 | | -# JSON Server v1 (Beta) |
| 1 | +# JSON-Server |
2 | 2 |
|
3 | | -Fast mock REST API from a JSON file. |
| 3 | +[](https://github.com/typicode/json-server/actions/workflows/node.js.yml) |
4 | 4 |
|
5 | | -> Beta note: v1 can still change. For stable v0.17 docs, see: |
6 | | -> https://github.com/typicode/json-server/tree/v0.17.4 |
| 5 | +> [!IMPORTANT] |
| 6 | +> Viewing beta v1 documentation – usable but expect breaking changes. For stable version, see [here](https://github.com/typicode/json-server/tree/v0.17.4) |
7 | 7 |
|
8 | | -## Quickstart (30s) |
| 8 | +> [!NOTE] |
| 9 | +> Using React ⚛️ and tired of CSS-in-JS? See [MistCSS](https://github.com/typicode/mistcss) 👀 |
9 | 10 |
|
10 | | -Install: |
| 11 | +## Install |
11 | 12 |
|
12 | | -```sh |
| 13 | +```shell |
13 | 14 | npm install json-server |
14 | 15 | ``` |
15 | 16 |
|
16 | | -Create `db.json`: |
| 17 | +## Usage |
| 18 | + |
| 19 | +Create a `db.json` or `db.json5` file |
17 | 20 |
|
18 | 21 | ```json |
19 | 22 | { |
| 23 | + "$schema": "./node_modules/json-server/schema.json", |
20 | 24 | "posts": [ |
21 | | - { "id": "1", "title": "Hello", "views": 100 }, |
22 | | - { "id": "2", "title": "World", "views": 200 } |
| 25 | + { "id": "1", "title": "a title", "views": 100 }, |
| 26 | + { "id": "2", "title": "another title", "views": 200 } |
| 27 | + ], |
| 28 | + "comments": [ |
| 29 | + { "id": "1", "text": "a comment about post 1", "postId": "1" }, |
| 30 | + { "id": "2", "text": "another comment about post 1", "postId": "1" } |
23 | 31 | ], |
24 | | - "comments": [{ "id": "1", "text": "Nice", "postId": "1" }], |
25 | | - "profile": { "name": "typicode" } |
| 32 | + "profile": { |
| 33 | + "name": "typicode" |
| 34 | + } |
26 | 35 | } |
27 | 36 | ``` |
28 | 37 |
|
29 | | -Run: |
| 38 | +<details> |
30 | 39 |
|
31 | | -```sh |
32 | | -npx json-server db.json |
| 40 | +<summary>View db.json5 example</summary> |
| 41 | + |
| 42 | +```json5 |
| 43 | +{ |
| 44 | + posts: [ |
| 45 | + { id: "1", title: "a title", views: 100 }, |
| 46 | + { id: "2", title: "another title", views: 200 }, |
| 47 | + ], |
| 48 | + comments: [ |
| 49 | + { id: "1", text: "a comment about post 1", postId: "1" }, |
| 50 | + { id: "2", text: "another comment about post 1", postId: "1" }, |
| 51 | + ], |
| 52 | + profile: { |
| 53 | + name: "typicode", |
| 54 | + }, |
| 55 | +} |
33 | 56 | ``` |
34 | 57 |
|
35 | | -Try: |
| 58 | +You can read more about JSON5 format [here](https://github.com/json5/json5). |
36 | 59 |
|
37 | | -```sh |
38 | | -curl http://localhost:3000/posts/1 |
| 60 | +</details> |
| 61 | + |
| 62 | +Pass it to JSON Server CLI |
| 63 | + |
| 64 | +```shell |
| 65 | +$ npx json-server db.json |
39 | 66 | ``` |
40 | 67 |
|
41 | | -Response: |
| 68 | +Get a REST API |
42 | 69 |
|
43 | | -```json |
| 70 | +```shell |
| 71 | +$ curl http://localhost:3000/posts/1 |
44 | 72 | { |
45 | 73 | "id": "1", |
46 | | - "title": "Hello", |
| 74 | + "title": "a title", |
47 | 75 | "views": 100 |
48 | 76 | } |
49 | 77 | ``` |
50 | 78 |
|
| 79 | +Run `json-server --help` for a list of options |
| 80 | + |
| 81 | +## Sponsors ✨ |
| 82 | + |
| 83 | +### Gold |
| 84 | + |
| 85 | +| | |
| 86 | +| :--------------------------------------------------------------------------------------------------------------------------------------------------------: | |
| 87 | +| <a href="https://mockend.com/" target="_blank"><img src="https://jsonplaceholder.typicode.com/mockend.svg" height="100px"></a> | |
| 88 | +| <a href="https://zuplo.link/json-server-gh"><img src="https://github.com/user-attachments/assets/adfee31f-a8b6-4684-9a9b-af4f03ac5b75" height="100px"></a> | |
| 89 | +| <a href="https://www.mintlify.com/"><img src="https://github.com/user-attachments/assets/bcc8cc48-b2d9-4577-8939-1eb4196b7cc5" height="100px"></a> | |
| 90 | +| <a href="http://git-tower.com/?utm_source=husky&utm_medium=referral"><img height="100px" alt="tower-dock-icon-light" src="https://github.com/user-attachments/assets/b6b4ab20-beff-4e5c-9845-bb9d60057196" /></a> |
| 91 | + |
| 92 | +### Silver |
| 93 | + |
| 94 | +| | |
| 95 | +| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | |
| 96 | +| <a href="https://requestly.com?utm_source=githubsponsor&utm_medium=jsonserver&utm_campaign=jsonserver"><img src="https://github.com/user-attachments/assets/f7e7b3cf-97e2-46b8-81c8-cb3992662a1c" style="height:70px; width:auto;"></a> | |
| 97 | + |
| 98 | +### Bronze |
| 99 | + |
| 100 | +| | | |
| 101 | +| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | |
| 102 | +| <a href="https://www.storyblok.com/" target="_blank"><img src="https://github.com/typicode/json-server/assets/5502029/c6b10674-4ada-4616-91b8-59d30046b45a" height="35px"></a> | <a href="https://betterstack.com/" target="_blank"><img src="https://github.com/typicode/json-server/assets/5502029/44679f8f-9671-470d-b77e-26d90b90cbdc" height="35px"></a> | |
| 103 | + |
| 104 | +[Become a sponsor and have your company logo here](https://github.com/users/typicode/sponsorship) |
| 105 | + |
| 106 | +## Sponsorware |
| 107 | + |
| 108 | +> [!NOTE] |
| 109 | +> This project uses the [Fair Source License](https://fair.io/). Only organizations with 3+ users are kindly asked to contribute a small amount through sponsorship [sponsor](https://github.com/sponsors/typicode) for usage. **This license helps keep the project sustainable and healthy, benefiting everyone.** |
| 110 | +> |
| 111 | +> For more information, FAQs, and the rationale behind this, visit [https://fair.io/](https://fair.io/). |
| 112 | +
|
51 | 113 | ## Query capabilities overview |
52 | 114 |
|
53 | 115 | ```http |
|
0 commit comments