Consider animals being some REST resources. User has animals assigned to him.
The endpoint /api/animals/{animalId}/feed
is used to feed a given animal by the authenticated user.
User should not be able to feed animals he does not own. What HTTP status code should be emitted in such a scenario?
400, 401, 403, 404, something else?
Also, should the situation where passing animalId
that does not exist, e.g. 123456789 be distinguished from the situation where animalId
does not belong to the logged in user?
I personally feel like I should return 404 in all cases.
This seems like a typical REST design situation, so I am wondering how experienced devs would solve it.
/api/animals/{animalId}/feed
for ananimalId
not owned by the current user would get you a 404, because it doesn't exist for the current user. If the animalId exists for the current users tenanted data set, but they don't have permission to feed or access the animal (ie the animal exists in the current users tenanted data set, but they specifically dont have access to it), then its a 401. So the setup of the system is important here, is what I'm trying to say. – Moo Jan 17 '21 at 20:47