0Pricing
API Rate Limiting & Scalability Patterns · درس

إبلاغ عملاء API بالحدود

تعلّم اصطلاحات HTTP لإبلاغ العملاء بحدود المعدل، بما في ذلك رمز الحالة 429 وRetry-After ورؤوس RateLimit التي تمكّن العملاء من التصرف بشكل سليم.

إبلاغ عملاء API بالحدود درس مجاني في API Rate Limiting & Scalability Patterns على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في API Rate Limiting & Scalability Patterns، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة API Rate Limiting & Scalability Patterns 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Limits Need Communication

A limit that silently drops requests frustrates devs. A good API tells clients their usage, when they'll be throttled, and when to retry.

The 429 Status Code

When a client exceeds its allowance, return 429 Too Many Requests — the universal signal that the request was throttled, not a server error.

HTTP/1.1 429 Too Many Requests
Content-Type: application/json

{ "error": "rate_limit_exceeded" }

Why Not 503

Don't use 503 or 500 for throttling — they imply the server is broken. 429 is specific: the client's fault, and it's temporary.

The Retry-After Header

Pair a 429 with a Retry-After header — seconds or an HTTP date — and well-behaved clients wait instead of hammering the server.

HTTP/1.1 429 Too Many Requests
Retry-After: 30

Proactive Headers

Add proactive headers on successful responses too, reporting remaining quota so clients self-throttle before they ever hit a 429.

RateLimit-Limit: 100
RateLimit-Remaining: 42
RateLimit-Reset: 30

Header Naming

Old APIs used X-RateLimit-*; the IETF draft uses unprefixed RateLimit-*. Pick one convention and document it — consistency beats the name.

Reset Semantics

The reset value is either seconds until the window resets or an absolute timestamp. Document which, or clients will retry too early.

A Clear Error Body

Beyond headers, return a structured JSON error body with the limit, what's left, and a human-readable message to aid debugging.

{
  "error": "rate_limit_exceeded",
  "limit": 100,
  "retry_after": 30,
  "message": "Slow down and retry in 30 seconds."
}

Client-Side Behavior

Good clients read these signals and apply exponential backoff with jitter on a 429 instead of retrying instantly — Retry-After nudges them.

Documenting Limits

Document your limits, header names, and reset semantics. Predictable, published limits let integrators build resilient apps and cut support load.

Putting It Together

The complete response: a 429 status, Retry-After, the RateLimit trio, and a descriptive JSON body — turning a rejection into guidance.

Quick Check

Status code, headers, error body — which signals actually tell clients about the limit?

Recap

Recap: throttle with 429 (not 5xx), add Retry-After, send RateLimit-Limit/Remaining/Reset so clients self-throttle, and document it all.

الأسئلة الشائعة

هل درس «إبلاغ عملاء API بالحدود» مجاني؟

نعم — نص درس «إبلاغ عملاء API بالحدود» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة API Rate Limiting & Scalability Patterns، انتقل إلى CoddyKit PRO. تتضمن دورة API Rate Limiting & Scalability Patterns 4 دروس في المجموع.

ماذا ستتعلم في «إبلاغ عملاء API بالحدود»؟

تعلّم اصطلاحات HTTP لإبلاغ العملاء بحدود المعدل، بما في ذلك رمز الحالة 429 وRetry-After ورؤوس RateLimit التي تمكّن العملاء من التصرف بشكل سليم. تتمرن على API Rate Limiting & Scalability Patterns مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ API Rate Limiting & Scalability Patterns؟

لا تُشترط خبرة سابقة. API Rate Limiting & Scalability Patterns على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «إبلاغ عملاء API بالحدود»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس API Rate Limiting & Scalability Patterns هذا؟

نعم. كل درس في API Rate Limiting & Scalability Patterns يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ما المقصود بتحديد معدل API؟
  2. لماذا يُعد تحديد المعدل أمرًا بالغ الأهمية؟
  3. مفاهيم تحديد المعدل الأساسية
  4. إبلاغ عملاء API بالحدود
← العودة إلى API Rate Limiting & Scalability Patterns