انتقل إلى المحتوى
أمين أبوزيد
JNR-017

HTTP بعمق

  • 6 درس
  • 2 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • الطرق (Methods)
  • عدم تأثر النتيجة بالتكرار (Idempotency)
  • الطرق الآمنة (Safe methods)
  • الترويسات (Headers)
  • التفاوض على المحتوى (Content negotiation)
  • التخزين المؤقت (Caching)

تعلّم أولًا

2 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Classify methods as safe and/or idempotent and explain why it matters for retries.
  2. Use request and response headers for content negotiation (Accept, Content-Type).
  3. Explain HTTP caching (Cache-Control, ETag, conditional requests) and when to disable it.
  4. Explain HTTP versions and connection reuse at a conceptual level.

الدروس

  1. 01نظرة ثانية على الطرق: الأمان وعدم تأثر النتيجة بالتكرار
  2. 02الترويسات المهمة لمهندسي الواجهة الخلفية
  3. 03التفاوض على المحتوى (Content negotiation)
  4. 04التخزين المؤقت والطلبات الشرطية
  5. 05HTTP/1.1 وHTTP/2 وHTTP/3 باختصار
  6. 06عرض عملي: GET شرطي مع ETags وcurl

المختبر والتمارين

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)

IDOutcomeTask
JNR-017-EX011Classify GET, HEAD, POST, PUT, PATCH, DELETE as safe and/or idempotent in a table.
JNR-017-EX021A client retries POST /orders after a timeout. Describe what can go wrong and one way to prevent it.
JNR-017-EX032Make GET /products/{id} return JSON only and show the status for Accept: application/xml.
JNR-017-EX043Choose a Cache-Control value for: a public product image, a user's order list, a bank balance. Justify each.
JNR-017-EX053Using curl -i, record a 200 with ETag and then a 304 for the same URL.
JNR-017-EX064Write 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 gives 406.
  • EX04 Image: public, max-age=86400. Order list: private, no-cache (or short private max-age). Balance: no-store.
  • EX05 curl -i URL then curl -i -H 'If-None-Match: "<etag>"' URL; second response has 304 and 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.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which method is safe?O1
  2. 2Which method is idempotent but not safe?O1
  3. 3Why does idempotency matter?O1
  4. 4The Accept header says:O2
  5. 5A client posts a body type the server cannot read. Expected status:O2
  6. 6A 304 response means:O3
  7. 7Which header sends the client's stored ETag back?O3
  8. 8Which is right for a response with a user's private data?O3
  9. 9HTTP/2 multiplexing means:O4
  10. 10Why reuse connections?O4

الجزء العملي

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).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.