假设我们有以下服务器资源:
api.example.com/event/1
它返回一些任意资源,例如:
{
id: 1,
details: {
type: 'webinar',
....
},
attendees: [
{
user_id: 1,
first_name: 'Bob'
...
},
...
]
}
对于客户来说,请求仅获取事件的事件详细信息而不是与会者列表可能很有用。
如果客户想要两个资源,最好为资源提供两个单独的 URL 并强制两个单独的请求?
api.example.com/event/{event_id}
api.example.com/attendees/{event_id}
还是提供相同的两个端点更好,但可以选择让第一个端点支持 GET 参数以打开或关闭与会者列表
api.example.com/event/{event_id}?listAttendees={true|false}
api.example.com/attendees/{event_id}
listAttendees
参数将在哪里让表示返回与会者列表或不返回。
允许 GET 参数更改从特定 URL 返回的表示是一种常见的做法吗?