I am creating a simple REST API that outputs JSON data. However I am not sure what should be returned if I make an request to a resource which has no data to return:
What of the below shown alternatives would be appropriate to use when requesting /users and /users/:id when there are no users at all, or the specific user can’t be found?
[]andHTTP 200- Empty response with a
HTTP 410 - Gone? - Empty response with a
HTTP 404 - missing - Something else?
GET /usersshould return aHTTP 200with a response of[]or aHTTP 204with an empty response.GET /users/:idshould return aHTTP 404. You can return a custom error message as the response if you want.