Responses

Client errors

Distinguish bad input, missing authentication, forbidden access, missing resources, conflicts, and rate limits using common 4xx responses.

8 minute lesson

~~~

Use a 4xx response when the server cannot fulfill the request as sent.

  • 400 Bad Request: invalid syntax or input.
  • 401 Unauthorized: authentication is missing or invalid.
  • 403 Forbidden: the user is known but not allowed.
  • 404 Not Found: the target resource does not exist.
  • 409 Conflict: the request conflicts with current state.
  • 422 Unprocessable Content: the body is understood but fails semantic validation.
  • 429 Too Many Requests: the client exceeded a rate limit.

A useful error response explains what the client can fix. An API might return JSON with an error code and field-level details, while an HTML site may render a helpful page.

Do not leak secrets, stack traces, or database details in a public error body.

Lesson completed