For example, if I call GET to get an item, delete it with DELETE and GET it again, how should the second GET work?
I mean, by correctly following REST principles, what is the right approach in doing this since GET can be cached and all? What's the approach for handling stale data in REST?
First of all, the behavior depends on what the DELETE call returned as its response code.
If DELETE returns 200 - OK
or 204 - No Content
then the client should get 404 - Not Found
on its next call to GET. That's because 202 and 204 mean that the resource was deleted immediately.
However if DELETE returns 202 - Accepted
, there's a chance that the client will be able to successfully GET the resource for some time afterwards. That's because 202 means that the resource has been marked for deletion, but not necessarily cleaned up immediately.
Secondly, if there's a cache involved, the behavior should be built to be consistent with what would happen if there was no cache present. A successful DELETE should always lead to a removal both from the true origin of the data in addition to any cached copies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With