Repaso
Español
Backend & APIsCoreAPI-35

GET /users/9999 and that user does not exist. Correct status code?

Options

  1. 200 with empty body
  2. 404 Not Found (Correct option)
  3. 500 Internal Server Error
  4. 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.

Key terms

Practice this question in Repaso