知识卡片
接受响应给出追踪资源
耗时工作可先返回202 Accepted,表示已接收,尚未证明业务完成。响应给出延迟状态资源、刷新间隔、状态和完成/失败链接;客户端随后GET查看进度,再去最终资源取结果。
初次确认甚至可以早于实际开工,因此接口必须事前说明哪些动作可能延迟。取消能力取决于底层动作能否撤销;涉及写入不能只删追踪记录就算取消。完成后的追踪文档可保留用于核查。
结构图:
sequenceDiagram
participant 客户端
participant 接口
participant 后台处理
客户端->>接口: 提交耗时请求
接口-->>客户端: 202与状态资源链接
接口->>后台处理: 排队或执行
客户端->>接口: GET状态资源
接口-->>客户端: 当前状态与刷新建议
后台处理-->>接口: 完成或失败
客户端->>接口: 再次GET状态资源
接口-->>客户端: 最终状态与结果链接
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体工作流 · 查看原书依据
In cases where the response to an HTTP request is likely to be delayed (take more than a few seconds), you can use a delayed response pattern. This is done by returning a 202 Accepted status from the service along with metadata (via body and/or headers) that informs the client application of the status of the request, plus options to take additional action (like refresh or cancel).
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第7章《超媒体工作流》§7.15(来源项目:book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch07.xhtml)
- 结论依据:原文以耗时工作可先返回202 Accepted,表示已接收,尚未证明业务完成的方式说明该用途;同节示例与讨论补充了卡内条件和边界。
- 原始内容:In cases where the response to an HTTP request is likely to be delayed (take more than a few seconds), you can use a delayed response pattern. This is done by returning a 202 Accepted status from the service along with metadata (via body and/or headers) that informs the client application of the status of the request, plus options to take additional action (like refresh or cancel).