知识卡片
路径与方法共同定端点
同一 URL 路径可承载不同 API 端点:/orders 的 GET 获取订单列表,POST 创建订单;/orders/{order_id} 又可配合 GET、PUT、DELETE。设计接口时应同时核对路径和 HTTP 方法,不能把“有四条路径”误当作“只有四个操作”。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 2 章《A basic API implementation》(源文件:_epub-src/OEBPS/Text/02.htm)
- 结论依据:2.1 节的订单规范有四条 URL 路径,却由不同方法组成七个端点;同一路径 `/orders` 明确承载列表读取和创建两种操作。
- 原始内容:As you can see in figure 2.1, the API specification describes a REST API with four main URL paths: /orders —Allows us to retrieve lists of orders (GET) and create orders (POST). /orders/{order_id} —Allows us to retrieve the details of a specific order (GET), to update an order (PUT), and to delete an order (DELETE).