typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.83k stars 7.02k forks source link

Referential integrity #89

Open gr0uch opened 9 years ago

gr0uch commented 9 years ago

From my brief inspection of the source code, there is no concept of foreign keys or side effects. For example, if I make this request:

DELETE /posts/1

And subsequently make this request:

GET /comments/1

In the response there is still postId: 1, even though it doesn't exist.

typicode commented 9 years ago

Actually, there is. It's maybe not very visible.

You can find tests here: https://github.com/typicode/json-server/blob/master/test/index.js#L294 https://github.com/typicode/json-server/blob/master/test/utils.js#L10

What's the content of your db.json?

gr0uch commented 9 years ago

Oh nevermind, I tried it and what I got was unexpected, the comment disappeared! I expected the comment to still exist, but without the postId property. I should have changed my original post to another example to make it more clear what I mean by referential integrity:

In db.json is exactly what's in the README, then I make this request:

$ curl -X PATCH -H "Content-Type: application/json" -d '{"postId":2}' http://localhost:3000/comments/1

I expect this request to fail because the post with ID 2 does not exist, but it works anyways and now there is no referential integrity.

typicode commented 9 years ago

That's very good points, thanks :) I'll see what can be done for that.