根据最佳实践和 Richardson maturity 的原则,当你想在 RESTful API 中创建一个端点来返回一个有地址的客户列表和另一个没有地址的客户列表时,使用接收的单个端点是否更合适通过查询字符串“includeAddresses”的布尔参数或创建单独的端点?
具有查询字符串参数的相同端点:
获取 http://api.example.com/customers/1?includeAddresses=true
单独的端点:
获取http://api.example.com/customers/1/with-addresses.
获取http://api.example.com/customers/1/without-addresses
// 查询字符串:
[HttpGet("{customerId}")]
公共异步任务 GetCustomerById(int customerId,bool includeAddresses = false)
// 不同的端点:
[HttpGet("with-addresses/{customerId}")]
公共异步任务
[HttpGet("没有地址/{customerId}")]
公共异步任务