リダイレクトコードが 5 つあるのは、仕様とブラウザの間の 20 年来の不和のせいです。HTTP/1.0 は 301 と 302 をメソッド保存として定義しました。302 でリダイレクトされた POST は、新しい場所へ再 POST されるべきだったのです。ブラウザはこれを無視してメソッドを GET に書き換え、その挙動は広まりすぎて直せませんでした。HTTP/1.1 は争う代わりに現実を成文化しました。「あちらのリソースを GET しに行け」を意味する 303 See Other が作られ(リロード時のフォーム再送信を防ぐ POST-redirect-GET パターンの背骨)、307 Temporary Redirect が本来の厳密な意味 — 同じメソッド、同じボディ、保証付き — を復元し、RFC 7538 が 2015 年に 301 のメソッド保存版の双子である 308 Permanent Redirect でマス目を完成させました。
メンタルモデルは 2x2 の行列です。恒久か一時か、メソッド変更許容かメソッド保存必須かの掛け合わせ。301 と 302 はレガシーの隅(メソッドが GET に変わりうる)、308 と 307 は厳密な隅です。POST・PUT・DELETE を受ける API エンドポイントでは、この区別は飾りではありません — アップロードを 301 でリダイレクトすると、多くのクライアントでボディなしの GET へ静かに変換され、リクエストデータは蒸発します。
恒久性には牙があります。ブラウザは 301 と 308 を積極的に、しばしば無期限にキャッシュします。誤った恒久リダイレクトは、サーバーが送信をやめた後もローカルキャッシュから発火し続けます — ユーザーには、あなたが遠隔で起こせないキャッシュ削除が必要になります。定石はこうです: 危険なリダイレクトはまず 302/307 で配備し、様子を見てから 301/308 へ昇格させる。検索エンジンは 301/308 を「ランキングシグナルを新 URL へ移転」と扱うため、ドメイン移行や HTTPS 化の正解であり、理想的には数か月維持します。
method may → GET method preserved
permanent 301 Moved 308 Permanent Redirect
temporary 302 Found 307 Temporary Redirect
after POST 303 See Other → always GET (PRG pattern)
# Verify what a redirect really does:
curl -si -X POST https://example.com/old | head -3
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new
# many clients will now GET /new — the POST body is gone
429 Too Many Requests(コア仕様ではなく RFC 6585 で定義)は、プロトコルのバックプレッシャー弁です。リクエストは理解された、ただクライアントが速く送りすぎているだけ。行儀のよい 429 は Retry-After ヘッダーを伴います。形式は 2 つ — デルタ秒(Retry-After: 30)か絶対時刻の HTTP-date — で、クライアントは自分の勝手なスケジュールで再試行するのではなく、これを尊重すべきです。実際の API の多くはクォータのテレメトリヘッダー(X-RateLimit-Limit / Remaining / Reset の一族。RateLimit フィールドとして標準化が進行中)を添えて、クライアントが壁にぶつかった後ではなく、ぶつかる前に自らペースを整えられるようにしています。
そもそも再試行すべきかは 3 つの問いで決まります。この失敗は再試行可能か? 5xx は概ねイエス、4xx は概ねノー — リクエスト自体が欠陥だからで、例外は 408、429、そして(慎重にであれば)425。このメソッドは繰り返しても安全か? GET・PUT・DELETE は冪等と定義されています。送信途中でタイムアウトした POST は見えないところで成功していたかもしれず、盲目的な POST 再試行は二重課金の危険があります — 決済 API が冪等性キーを追加する理由です。再試行の間隔は? ジッター付きの指数バックオフです。同じ固定スケジュールで再試行するクライアントの群れは波として再同期し、回復途上のサーバーを再び押し潰します。
インシデント対応では、5xx の三兄弟がトリアージの地図になります。502 Bad Gateway: プロキシはアップストリームに到達したがゴミが返ってきた — アプリのプロセスを見る(クラッシュ、OOM)。503 Service Unavailable: 意図的な拒否 — 過負荷、メンテナンス、ヘルスチェック失敗。Retry-After を含むことがあります。504 Gateway Timeout: アップストリームが時間内に応答しなかった — 遅いクエリ、デッドロック、枯渇したコネクションプールを見る。
HTTP/1.1 429 Too Many Requests
Retry-After: 30
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1751414460
Retry decision cheat sheet:
408, 429, 5xx → retry with exponential backoff + jitter
other 4xx → do not retry; fix the request
POST → only retry with an idempotency key
backoff: 1s → 2s → 4s → 8s (+ random jitter each step)
Type a code (404), partial name (gateway), or keyword (auth) into the search box.
Browse the filtered list grouped by status class.
Read the canonical name and one-line description for the matching codes.
Use the colour coding to quickly spot 4xx (client error) vs 5xx (server error).
Reference the result in your API design, log analysis, or error handling code.
主な使用例
Choosing the right status code for a new REST API endpoint.
Investigating a strange status code (e.g., 418, 451) you saw in a server log.
Deciding between 401 Unauthorized and 403 Forbidden for an auth flow.
Documenting expected error responses in an OpenAPI / Swagger spec.
Understanding why a CDN returned 503 vs 504 during an outage.
Mapping HTTP errors to user-facing error messages with consistent semantics.
よくある質問
Q. When should I return 401 vs 403?
A. 401 means "not authenticated, present credentials"; 403 means "authenticated but not allowed". If the client has no valid session, send 401. If they are logged in but lack permission, send 403.
Q. Is 422 the same as 400?
A. Both are 4xx, but 400 means the request itself is malformed (bad JSON, missing header) while 422 means the request is well-formed but semantically invalid (validation failed).
Q. Should I always use 200 for successful POSTs?
A. 201 Created is more precise when you create a new resource and 204 No Content when you succeed but return no body. 200 is correct when you do return a representation.
Q. What does 429 mean for rate limiting?
A. 429 Too Many Requests signals the client should slow down. Pair it with a Retry-After header so clients know when to try again.