【发布时间】:2017-11-04 06:21:43
【问题描述】:
假设我有两个对象,用户和约会,其中用户可能有一个或多个约会。
我很好奇我是否应该允许 API 的使用者通过 Appointments 控制器中的用户“过滤”。以下是我想到的 GET 操作调用:
Users Controller
GET
api/Users
api/Users/{userId}
api/Users/{userId}/Appointments
api/Users/{userId}/Appointments/{appointmentId}
Appointments Controller
GET
api/Appointments/
api/Appointments/{appointmentId}
我很好奇在 Appointments 控制器上为用户实现过滤器是否是一个好主意(良好做法)......所以上面的调用将变为:
Appointments Controller
GET
api/Appointments/{userId:int?}
api/Appointments/{appointmentId}
在上述调用中,我为 userId 添加了一个可选的查询字符串参数,该参数默认为 null。这将允许呼叫者获取所有约会,或通过 userId 获取约会。
我想我不太确定什么是具有关系的对象的最佳实践。
【问题讨论】:
标签: c# asp.net-web-api routing attributerouting