HTTP بعمق
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- الطرق (Methods)
- عدم تأثر النتيجة بالتكرار (Idempotency)
- الطرق الآمنة (Safe methods)
- الترويسات (Headers)
- التفاوض على المحتوى (Content negotiation)
- التخزين المؤقت (Caching)
تعلّم أولًا
2 ساعة تدريب (تقدير)
مخرجات التعلم
- Classify methods as safe and/or idempotent and explain why it matters for retries.
- Use request and response headers for content negotiation (
Accept,Content-Type). - Explain HTTP caching (
Cache-Control,ETag, conditional requests) and when to disable it. - Explain HTTP versions and connection reuse at a conceptual level.
الدروس
المختبر والتمارين
Lab
JNR-017-LAB1 · ETags
Outcomes: 1–4 · Time: ~2 h Add ETag support to GET /products/{id} in the Shop API. Derive the ETag from the product's content or version. Honor If-None-Match by returning 304 Not Modified with no body. Show the full exchange with curl -i.
Acceptance: the second request (with If-None-Match) returns 304 with no body; after an update the ETag changes and the response is 200.
Exercises (assessment: quiz plus lab)
| ID | Outcome | Task |
|---|---|---|
| JNR-017-EX01 | 1 | Classify GET, HEAD, POST, PUT, PATCH, DELETE as safe and/or idempotent in a table. |
| JNR-017-EX02 | 1 | A client retries POST /orders after a timeout. Describe what can go wrong and one way to prevent it. |
| JNR-017-EX03 | 2 | Make GET /products/{id} return JSON only and show the status for Accept: application/xml. |
| JNR-017-EX04 | 3 | Choose a Cache-Control value for: a public product image, a user's order list, a bank balance. Justify each. |
| JNR-017-EX05 | 3 | Using curl -i, record a 200 with ETag and then a 304 for the same URL. |
| JNR-017-EX06 | 4 | Write three sentences: what connection reuse is and what HTTP/2 adds over HTTP/1.1. |
أظهر الحلول
- EX01 Safe: GET, HEAD. Idempotent: GET, HEAD, PUT, DELETE. PATCH and POST are neither guaranteed.
- EX02 The server may create two orders. Prevent with an idempotency key header that the server remembers (covered later in MID-029).
- EX03
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE); XML request gives406. - EX04 Image:
public, max-age=86400. Order list:private, no-cache(or shortprivatemax-age). Balance:no-store. - EX05
curl -i URLthencurl -i -H 'If-None-Match: "<etag>"' URL; second response has304and no body. - EX06 Connection reuse avoids repeated TCP/TLS setup; HTTP/2 multiplexes many requests on one connection and compresses headers.
Outcome 2 (headers) is also checked by quiz Q04 and Q05; outcome 4 by quiz Q09 and Q10.
الاختبار
Outcomes: O1 safe and idempotent · O2 content negotiation · O3 caching · O4 HTTP versions.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Six exercises JNR-017-EX01 to EX06 plus the ETag lab. Pass: at least five exercises and a lab where the second request returns 304 with no body.
أخطاء شائعة
POST for everything; non-idempotent PUT; caching personalized responses.
التقييم
Quiz plus lab.
الصلة بالمسار الوظيفي
Retries and idempotency (MID-029, MID-033).