انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-017-L03

التفاوض على المحتوى (Content negotiation)

  • الدرس 3 من 6
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

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

في هذا الدرس

let the client and server agree on a format.

الموضوعات المخطط لها

  • The client says what it can read with Accept. The server says what it sent with Content-Type.
  • Accept: application/json asks for JSON. Accept: application/xml asks for XML.
  • If the server cannot produce the requested type, it answers 406 Not Acceptable.
  • If the client sends a body type the server cannot read, the answer is 415 Unsupported Media Type.
  • In Spring, produces and consumes on a mapping declare what an endpoint supports.
تفاصيل المخطط المبدئي

عرض عملي

java
@GetMapping(value = "/products/{id}", produces = "application/json")
Product get(@PathVariable long id) { ... }

اختبر فهمك

Which status does a client get when it posts XML to a JSON-only endpoint?

أظهر الإجابة

415.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

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

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

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