How to Use This Tool
Search for a code, or use the picker to work backwards from what you are trying to say. Each entry notes whether it is cached and whether it preserves the request method, since those are the properties that cause trouble.
The four redirects
| Code | Duration | Method | Cached |
|---|---|---|---|
301 | permanent | may become GET | yes, often forever |
302 | temporary | may become GET | no |
307 | temporary | preserved | no |
308 | permanent | preserved | yes |
301 and 302 predate the rule about method preservation, and browsers historically converted a redirected POST into a GET with no body. That behaviour is now specified, so it is not a bug you can report — it is what those codes mean. If a redirect might ever receive a POST, use 307 or 308.
Why a wrong 301 is so painful
Browsers cache a 301 aggressively, frequently for the lifetime of the profile, and often without honouring cache headers. So a 301 issued by mistake keeps redirecting returning visitors long after the server has stopped sending it, and there is no way to reach into their browser and undo it.
The practical rule: use 302 or 307 while you are still deciding, and switch to 301 or 308 once the move is genuinely permanent. Going from temporary to permanent is easy; going the other way is not.
The codes people reach for wrongly
- 200 with an error inside. Returning
{"error": "not found"}with a 200 means every proxy, cache and monitoring tool believes the request succeeded. The status line is the machine-readable part; use it. - 400 versus 422. 400 is for a request the server cannot parse. 422 is for one that parsed fine and failed validation. Both are widely used for both, so pick one and be consistent within your API.
- 404 versus 410. 404 means "not here". 410 means "was here, deliberately gone" and tells search engines to drop it faster. Almost nobody uses 410, and it is the more honest answer after deleting something on purpose.
- 429. Rate limiting. Send
Retry-Afterwith it, or clients have to guess, and the ones that guess badly make your problem worse. - 503 versus 500. 503 means "temporarily down, try later" and can carry
Retry-After. 500 means "something broke and we do not know what". Maintenance should be 503, and monitoring treats them very differently.
A note on 418
418 I'm a teapot is from an April Fools' joke specification in 1998 and is not a real
status code. Several frameworks implement it anyway. It is harmless in a toy and out of place in
anything else.
