A 404 response in this case is pretty typical and easy for API users to consume.
One problem is that it is difficult for a client to tell if they got a 404 due to the particular entity not being found, or due to a structural problem in the URI. In your example, /foos/5
might return 404 because the foo with id=5 does not exist. However, /food/1
would return 404 even if foo with id=1
exists (because foos
is misspelled). In other words, 404 means either a badly constructed URI or a reference to a non-existent resource.
Another problem arises when you have a URI that references multiple resources. With a simple 404 response, the client has no idea which of the referenced resources was not found.
Both of these problems can be partially mitigated by returning additional information in the response body to let the caller know exactly what was not found.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…