Skip to content

Commit e87ef3e

Browse files
committed
fix: update readme
1 parent f5684d9 commit e87ef3e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,56 @@ npm install --save json-server-reset
1818

1919
## Use
2020

21+
If you are using [json-server](https://github.com/typicode/json-server), add this module as a middleware. For example, imagine our data file to be `data.json` with the following resources
22+
23+
```json
24+
{
25+
todos: []
26+
}
27+
```
28+
29+
Then load the file and this middleware
30+
31+
```
32+
json-server data.json --middlewares ./node_modules/json-server-reset
33+
```
34+
35+
Then you can work with "todos" and reset the datastore (I am using [httpie](https://httpie.org/) client in this examples)
36+
37+
```
38+
$ http :3000/todos
39+
[]
40+
$ http POST :3000/todos text="do something"
41+
{
42+
"id": 1,
43+
"text": "do something"
44+
}
45+
$ http POST :3000/todos text="do something else"
46+
{
47+
"id": 2,
48+
"text": "do something else"
49+
}
50+
$ http :3000/todos
51+
[
52+
{
53+
"id": 1,
54+
"text": "do something"
55+
},
56+
{
57+
"id": 2,
58+
"text": "do something else"
59+
}
60+
]
61+
```
62+
63+
Now reset the database back to the initial empty list of todos. Note `:=` syntax to send the JSON as a list, not as a string.
64+
65+
```
66+
$ http POST :3000/reset todos:=[]
67+
$ http :3000/todos
68+
[]
69+
```
70+
2171
### Small print
2272

2373
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2017

0 commit comments

Comments
 (0)