JSextonn
JSextonn

Reputation: 236

Correct to respond with 200 or 404 in the following scenario?

Lets say I have a URL /users/{id}/friends that returns a list of a specific users friends. If the id does not exist the response should be 404, but what about the case that the id does exist but does not have any friends? Should this be a 200 response with an empty array or 404?

Upvotes: 0

Views: 28

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596176

404 Not Found would not be appropriate when the id exists since it would have a friends list present, it would just potentially be an empty list. It would be more appropriate to send 200 OK with the actual list even if it is empty, or maybe send 204 No Content instead if it is actually empty. It depends on the nature of the request.

Upvotes: 1

Related Questions