1

Given a resource called pets, there should be two ways of retrieving the resource with the pet endpoint:

  1. GET .../pets/{petId} - retrieve a pet by its id
  2. GET .../pets/ - retrieves all pets

How should the API respond when the database doesn't find anything at the resource path?

My assumption is that:

  1. GET .../pets/{petId} -> results in a HTTP 404 (Not found / error). This is because the API has been requested to find a specific resource (petId), it is an error as that pet id doesn't exist.

  2. GET .../pets/ -> returns an empty array [] with HTTP 200 (ok). This is because the API has been requested to find all pet resources, the database just happens to not contain any.

Is this the right approach?

Is there any documentation / resources that explains what is meant to happen in this scnario? (I couldn't find anything using search)

zaza
  • 892
  • 1
  • 18
  • 37

0 Answers0