知识卡片
变更响应回显服务器状态
创建或更新资源后,响应可返回服务器保存的完整表示,让客户端核对实际结果。创建时尤其要包含服务器分配的 ID、创建时间、初始状态等只读属性;更新时回显最终表示,也能避免客户端继续依赖自己提交的旧值。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm)
- 结论依据:原文要求创建响应包含服务端设置的属性,并建议 POST、PUT/PATCH 后返回完整资源表示供客户端确认。
- 原始内容:The server also sets the time when the order was taken and its initial status. We call the properties set by the server server-side or read-only properties , and we must include them in the response payload. ... To update a resource, we use a PUT or a PATCH request . ... it’s also good practice to return a full representation of the resource, which the client can use to validate that the update was correctly processed.