Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle stale data in REST?

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?

like image 643
JohnDoDo Avatar asked May 24 '12 12:05

JohnDoDo


1 Answers

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.

like image 144
Brian Kelly Avatar answered Sep 30 '22 00:09

Brian Kelly