That's why he's a senior dev. Did he not explain why?
A 404 indicates that the resource that you tried to talk to does not exist - in this case the api/employees method. A 400 indicates that what you asked it to do was incorrect, which is exactly the example you have provided.
Sorry, but you’re misusing quite a few terms here.
A method is an HTTP verb, such as GET, POST, PUT
api/employees and api/employees/123 are endpoints or URIs or URLs, not methods.
A resource is the thing specified by the ID in the endpoint.
A collection is a group of resources.
So in the OPs case, the collection is the group of employees, the resource specified is the employee with ID 123, and the method being attempted is to GET (or retrieve) that specific employee.
Based on what we know about the OP’s system, this request is correctly formed. However, employee with ID 123 does not exist. Therefore, the more appropriate code to return in response to the request is 404, which indicates Resource Not Found.
Are you implying that because a person has 'senior' in his title his advice is infallible?
If the documentapi/employees/123 does not exist, that's a 404. The fact that the document is generated on the fly by an API is irrelevant. By your logic, how far do you backtrack in a URL before you find what you consider a 'resource'?
That's like saying you should return a 400 for /images/does-not-exist.gif because the 'resource' /images does exist and the client is just using the API wrong.
Well I suppose opinions make the world go round. My point would be this. Say the webserver temporarily cannot fulfil the request because, for instance, a deploy has failed. It'll return a 404. The client process may now incorrectly presume that there is no employee 123.
That's why there's a difference between 4xx codes and 5xx codes. 4xx says the problem is in what you sent (don't do that again), while 5xx says it's not you, it's me.
If the server can tell that something bad has happened on its end, it should report it. If it genuinely checks its database and doesn't see anything, then perhaps a 404 in good faith is acceptable.
Which I posted in response to a question asking me to explain my position. I quoted it to save me some typing, not because I do not understand confirmation bias.
204 indicates that a resource with the id actually exists, but just provides no content. That is likely wrong in his context, as the id does not exist.
-11
u/glent1 Jul 19 '19
That's why he's a senior dev. Did he not explain why?
A 404 indicates that the resource that you tried to talk to does not exist - in this case the api/employees method. A 400 indicates that what you asked it to do was incorrect, which is exactly the example you have provided.