واجهة API القابلة للتصفح ورموز الحالة
اختبار نقاط النهاية في المتصفح بطريقة صحيحة
واجهة API القابلة للتصفح ورموز الحالة درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Test in the Browser
DRF's browsable API renders any endpoint as an interactive web page, so you can explore and test your API without extra tools. 🌐
How It Decides
DRF uses content negotiation: browsers ask for HTML and get the friendly page, while code asking for JSON gets raw JSON instead.
Forms for Free
For write endpoints the browsable API even shows a form, letting you POST test data with a click instead of crafting curl commands.
Force JSON Anytime
Append ?format=json to any URL to skip the HTML page and see the exact JSON a real client would receive.
GET /api/books/?format=jsonStatus Codes Matter
Every API response carries an HTTP status code that tells the client what happened, far more reliably than reading the body text.
200 and 201
200 means a successful read, while 201 Created signals that a POST actually made a new resource, a small but important distinction.
Readable Constants
Instead of magic numbers, DRF gives you named constants in status so your code reads clearly and avoids typos like 20 versus 200.
from rest_framework import status
status.HTTP_201_CREATEDClient Errors: 400 and 404
The 4xx range blames the request: 400 means bad input that failed validation, and 404 means the resource simply was not found.
Response(serializer.errors, status=400)Server Errors: 500
A 500 means your code crashed, not the client. These signal bugs to fix, never something the caller did wrong.
Match Code to Outcome
Good APIs are predictable: return 201 on create, 400 on invalid input, 404 when missing. Correct status codes make clients trust you.
Browsable Plus Status
Together the browsable API and clear status codes make DRF endpoints easy to test by hand and easy for clients to consume.
Quick Check
Which status code best fits a successful POST that creates a record?
Recap: Test and Respond
You met the browsable API for hands-on testing and learned to return honest status codes like 200, 201, 400, and 404. ✅
الأسئلة الشائعة
هل درس «واجهة API القابلة للتصفح ورموز الحالة» مجاني؟
نعم — نص درس «واجهة API القابلة للتصفح ورموز الحالة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «واجهة API القابلة للتصفح ورموز الحالة»؟
اختبار نقاط النهاية في المتصفح بطريقة صحيحة تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «واجهة API القابلة للتصفح ورموز الحالة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تثبيت DRF وتهيئته
- Serializers: من النموذج إلى JSON
- APIView وFunction @api_view
- واجهة API القابلة للتصفح ورموز الحالة