Skip to content

Commit 8b3e48e

Browse files
committed
wip
1 parent 8d16c88 commit 8b3e48e

16 files changed

+7288
-0
lines changed

.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@typicode",
3+
"env":{
4+
"browser": true,
5+
"node": true
6+
}
7+
}

LICENSE

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Fair Source License, version 0.9
2+
3+
Copyright (C) 2023-present typicode
4+
5+
Licensor: typicode
6+
7+
Software: json-server
8+
9+
Use Limitation: 2 users
10+
11+
License Grant. Licensor hereby grants to each recipient of the
12+
Software ("you") a non-exclusive, non-transferable, royalty-free and
13+
fully-paid-up license, under all of the Licensor's copyright and
14+
patent rights, to use, copy, distribute, prepare derivative works of,
15+
publicly perform and display the Software, subject to the Use
16+
Limitation and the conditions set forth below.
17+
18+
Use Limitation. The license granted above allows use by up to the
19+
number of users per entity set forth above (the "Use Limitation"). For
20+
determining the number of users, "you" includes all affiliates,
21+
meaning legal entities controlling, controlled by, or under common
22+
control with you. If you exceed the Use Limitation, your use is
23+
subject to payment of Licensor’s then-current list price for licenses.
24+
25+
Conditions. Redistribution in source code or other forms must include
26+
a copy of this license document to be provided in a reasonable
27+
manner. Any redistribution of the Software is only allowed subject to
28+
this license.
29+
30+
Trademarks. This license does not grant you any right in the
31+
trademarks, service marks, brand names or logos of Licensor.
32+
33+
DISCLAIMER. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OR
34+
CONDITION, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES
35+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
36+
NONINFRINGEMENT. LICENSORS HEREBY DISCLAIM ALL LIABILITY, WHETHER IN
37+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38+
CONNECTION WITH THE SOFTWARE.
39+
40+
Termination. If you violate the terms of this license, your rights
41+
will terminate automatically and will not be reinstated without the
42+
prior written consent of Licensor. Any such termination will not
43+
affect the right of others who may have received copies of the
44+
Software from you.

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# json-server
2+
3+
[![Node.js CI](https://github.com/typicode/json-server/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/json-server/actions/workflows/node.js.yml)
4+
5+
## Usage
6+
7+
Install `json-server`
8+
9+
```shell
10+
npm install json-server
11+
```
12+
13+
Create a `db.json` file or run `json-server db.json` to create one with some default resources
14+
15+
```json
16+
{
17+
"posts": [
18+
{ "id": "1", "title": "string" },
19+
{ "id": "2", "title": "some post" }
20+
],
21+
"comments": [
22+
{ "id": "1", "text": "some text", "postId": "1" },
23+
{ "id": "2", "text": "some text", "postId": "1" }
24+
]
25+
}
26+
```
27+
28+
```shell
29+
json-server db.json
30+
```
31+
32+
Run `json-server --help` for a list of options
33+
34+
## Routes
35+
36+
```
37+
GET /posts
38+
GET /posts/:id
39+
POST /posts
40+
PUT /posts
41+
DELETE /posts/:id
42+
```
43+
44+
## Params
45+
46+
### Comparison
47+
48+
- ` ``==`
49+
- `lt``<`
50+
- `lte``<=`
51+
- `gt``>`
52+
- `gte``>=`
53+
- `ne``!=`
54+
55+
```
56+
GET /posts?views_gt=9000
57+
```
58+
59+
### Range
60+
61+
- `start`
62+
- `end`
63+
- `limit`
64+
65+
```
66+
GET /posts?_start=10&_end=20
67+
GET /posts?_start=10&_limit=10
68+
```
69+
70+
### Paginate
71+
72+
- `page`
73+
- `per_page` (default = 10)
74+
75+
```
76+
GET /posts?_page=1&_per_page=25
77+
```
78+
79+
### Sort
80+
81+
- `_sort=f1,f2`
82+
83+
```
84+
GET /posts?_sort=id,-views
85+
```
86+
87+
### Nested fields
88+
89+
- `x.y.z`
90+
91+
### Include
92+
93+
```
94+
GET /posts?_include=comments
95+
GET /comments?_include=post
96+
```
97+
98+
## Delete
99+
100+
```
101+
DELETE /posts/1
102+
DELETE /posts/1?_include=comments
103+
```
104+
105+
# Serving static files
106+
107+
If you create a `./public` directory, JSON Serve will serve its content in addition to the REST API. You can add custom directories using `-s/--static` option.
108+
109+
```sh
110+
json-server -s ./static
111+
json-server -s ./static -s ./node_modules
112+
```

0 commit comments

Comments
 (0)