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?
[]
and HTTP 200
HTTP 410 - Gone
?HTTP 404 - missing
GET /users
should return a HTTP 200
with a response of []
or a HTTP 204
with an empty response.
GET /users/:id
should return a HTTP 404
. You can return a custom error message as the response if you want.