Git-Hub repo with setup guide.
https://github.com/typicode/json-server
1) Install json server
Please visit the json-server official site and find this command.
Install json-server globaly into your system
-npm install -g json-server
2) Start json-server with command
Open cmd and go to the locaation where .json file present
run the this command
-npx json-server --watch db.json
3) Delete data with child table data (delete relation record).
Hi!
This is not a random error.
I found that if there is some kind of connection between elements, then DELETE request will erase both of them:
I have a "database":
{
"users":[
{"id":1, "name": "Bob", "email":"bob@gmailcom", "age": 35},
{"id":2, "name": "Sue", "email":"sue@gmailcom", "age": 32},
{"id":3, "name": "Cloe", "email":"cloe@gmailcom", "age": 19},
{"id":4, "name": "Jane", "email":"jane@gmailcom", "age": 26}
],
"comments":[
{"id":1, "message1": "Here should be some comment", "userId": 2},
{"id":2, "message2": "Here should be many comment", "userId": 4},
{"id":3, "message3": "Here should be more comment", "userId": 1}
]
}
and I run this from console:let fetchOpt = { method: "delete", mode: "cors", cache: "no-cache" }; fetch("http://localhost:3000/users/4", fetchOpt);
then server will delete "Jane with id:4" from users, and "message2 with userId: 4" from comments
Try it. Then I changed "userId" to "usr" and there is no more "strange delete"
Comments
Post a Comment