The five classes
- 1xx Informational: the request is in progress.
- 2xx Success: the request worked.
- 3xx Redirection: the client must go elsewhere or use its cache.
- 4xx Client error: the request was wrong; retrying unchanged won't help (except 408 and 429).
- 5xx Server error: the server failed; retrying with backoff may help.
Choosing codes for your API
- Use
400for malformed requests and422for validation errors in otherwise valid JSON. 401means "who are you?" and403means "I know who you are, and the answer is no."- Return
429with aRetry-Afterheader when rate limiting, so clients can back off politely. - Never return
200with an error message in the body. Clients, monitors and caches rely on the status code. - Pair codes with a consistent error body, for example
{"error":{"code":"invalid_email","message":"…","hint":"…"}}, or the RFC 9457 Problem Details format.