知识卡片
资源不存在返回404
按订单 ID 访问资源时,应先确认该 ID 对应的订单存在;找不到就返回 404,并给出有用的错误说明。这样调用方能区分“资源不存在”与成功响应,而不会把空结果误当成有效订单。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 2 章《A basic API implementation》(源文件:_epub-src/OEBPS/Text/02.htm)
- 结论依据:2.7 节的读取、更新、删除等处理函数遍历订单列表,未找到 ID 时抛出 404;正文总结每个按订单 ID 的端点都先检查资源是否存在。
- 原始内容:In every endpoint under the /orders/{order_id} URL path, we check whether the order requested by the API client exists, and if it doesn’t we return a 404 (Not Found) response with a helpful message.