知识卡片
撤销操作需保存历史
已提交的更新或删除后来需要撤回时,接口必须提供安全恢复路径,并考虑并发修改和下游影响。
单资源更新可以再发条件PUT写回旧值,前提是保留旧值并确认资源未被他人修改。删除没有通用UNDELETE方法,可设计undoDelete或rollback动作,用原地址及版本信息恢复;服务需保留可恢复历史。若一个动作影响多个资源和下游服务,撤销还需覆盖所有影响,不可把本地回写当成完整回滚。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体接口设计 · 查看原书依据
You might have issued an HTTP DELETE for a resource and want to recover that resource. There is no HTTP UNDELETE method. Instead you need to restore an existing record with a special command. The safest way is to create another, special operation (undoDelete) that uses HTTP PUT and some argument (usually the previous URL along with a validation value like the ETag header). This means the service interface needs to be designed to support this feature, including saving DELETEd resources in case they need to be restored!
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第03章《超媒体接口设计》(来源项目 book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch03.xhtml;小节:3.9)
- 结论依据:原文以单资源更新可以再发条件PUT写回旧值,前提是保留旧值并确认资源未被他人修改的机制或场景为依据;同小节余文补充本卡所列条件,按2022年原书语境整理。
- 原始内容:You might have issued an HTTP DELETE for a resource and want to recover that resource. There is no HTTP UNDELETE method. Instead you need to restore an existing record with a special command. The safest way is to create another, special operation (undoDelete) that uses HTTP PUT and some argument (usually the previous URL along with a validation value like the ETag header). This means the service interface needs to be designed to support this feature, including saving DELETEd resources in case they need to be restored!