Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个/users/{id}/friends返回特定用户朋友列表的 URL。如果 id不存在,则响应应该是404,但是 id存在但没有任何朋友的情况呢?这应该是200一个空数组的响应还是404?
/users/{id}/friends
404
200
404 Not Found当存在时不合适,id因为它会有一个朋友列表,它可能只是一个空列表。即使它是空的,使用实际列表发送会更合适200 OK,或者204 No Content如果它实际上是空的,则可以发送。这取决于请求的性质。
404 Not Found
id
200 OK
204 No Content