Skip to content
ADP
API Design PrincipleBETA

[ADP-139] Retry-After

reviewing phase 1

應統一回應內容

概述

Retry-After 標頭為客戶端提供了在收到某些狀態碼後何時重試請求的指導。本 ADP 概述了在 API 設計和實現中使用 Retry-After 標頭的最佳實踐。

指導原則

  • Retry-After 標頭應該(SHOULD)與適當的狀態碼一起使用,例如 429 (Too Many Requests) 和 503 (Service Unavailable)。
  • Retry-After 的值應該(SHOULD)是 HTTP 日期或延遲的秒數。
  • API 應(SHOUYLD)提供準確和合理的 Retry-After 值,以幫助客戶端有效管理其請求。
  • 可以在 301 (Moved Permanently) 回應中使用 Retry-After,以指示資源何時會在其新位置可用。

Retry-After 的格式

  1. HTTP 日期格式:

    http
    Retry-After: Fri, 31 Dec 2023 23:59:59 GMT
  2. 延遲秒數:

    http
    Retry-After: 120

範例

http
HTTP/1.1 429 Too Many Requests
Content-Type: application/problem+json
Content-Lauguage: zh-tw
Retry-After: 30
{
  "type": "https://example.com/problems/rate-limit-exceeded",
  "title": "超出速率限制",
  "status": 429,
  "detail": "您已超出速率限制。請在 30 秒後重試。",
  "retryAfter": 30
}

相關 ADP

參考資料