Search code examples
restconventions

Response for missing resources?


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?

  1. [] and HTTP 200
  2. Empty response with a HTTP 410 - Gone ?
  3. Empty response with a HTTP 404 - missing
  4. Something else?

Solution

  • 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.