GET /users/9999 and that user does not exist. Correct status code?
Options
- 200 with empty body
- 404 Not Found (Correct option)
- 500 Internal Server Error
- 401 Unauthorized
Answer
404 Not Found
Why
404 Not Found means the requested resource does not exist.
Returning 200 with an empty body confuses clients, who think it worked. 500 would suggest the server crashed, which is not the case.
Remember
Resource doesn't exist → 404.