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?


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.


As originally stated a GET following a DELETE should produce a HTTP 404 error irrespective of caching that may be in place. The logic code should be smart enough to remove the record from the persistent store as well as the in-memory store or cache. In addition the UI should be able to handle the result of the 404 with whatever flow or process you deem appropriate.

链接地址: http://www.djcxy.com/p/59838.html

上一篇: 如何使用C或C ++获取目录中的文件列表?

下一篇: 如何处理REST中的陈旧数据?