假设我有一个 RESTful API 方法来返回有关一系列位置的数据:
/地点
[{
location_id: 1,
location_name: 'Austin'
},{
location_id: 2,
location_name: 'San Francisco'
},{
location_id: 3,
location_name: 'Seattle'
}]
现在假设我想为每个位置返回一个汇总的employee_count:
[{
location_id: 1,
location_name: 'Austin',
employee_count: 96
},{
location_id: 2,
location_name: 'San Francisco',
employee_count: 71
},{
location_id: 3,
location_name: 'Seattle',
employee_count: 85
}]
那么,什么对 uri 最有意义呢?还是/地点?或者也许 /employees/locations?
我担心的是,每次对 /locations 的请求计算employee_count 可能会导致额外的、浪费的开销,因为employee_count 可能仅在5-10% 的时间内使用。