知识卡片
成功码匹配实际结果
成功响应要按实际结果选状态码:创建资源可用 201,普通成功可用 200;请求完成但不返回内容可用 204。方法是 POST 也不自动意味着 201,书中的取消与付款端点仅报告操作已处理,示例用 200。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm)
- 结论依据:原文在订单端点表中将创建、读取、删除和取消/付款分别配为 201、200、204、200,并解释 POST 不一定真的创建新资源。
- 原始内容:POST /orders : 201 (Created)—Signals that a resource has been created. ... DELETE /orders/{order_id} : 204 (No Content)—Signals that the request was successfully processed but no content is delivered in the response. ... POST /orders/{order_id}/cancel : 200 (OK)—Although this is a POST endpoint, we use the 200 (OK) status code since we’re not really creating a resource