Restful "secondary" 个表的资源命名

Restful resource naming for "secondary" tables

让我们以我的例子为例,我有 3 个表,我想知道什么是命名我的资源的最佳方法 url。

:

  1. 建筑物
  2. building_type定义最简单的就是#1.

API 资源:

  1. GET someapi.com/buildings
  2. GET someapi.com/**?**

我的问题是我不知道 "secondary tables" 的最佳实践是什么,例如 building_type。

可能:

希望大家多多指教。谢谢。

您首先需要弄清楚我们对您的API、场景、用例等的要求,然后才真正开始构建它。

回到你的问题,我会选择 GET someapi.com/buildingTypes,因为 /buildings/types 会给你留下一个 "Types" 资源,它本身没有多大意义.你确实可以做到这一点,所以它只有在你进入建筑资源后才能访问,所以 GET someapi.com/buildings/buildingTypes 可能是 navigate 的方式。