التفاوض على المحتوى (Content negotiation)
في هذا الدرس 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 withContent-Type. Accept: application/jsonasks for JSON.Accept: application/xmlasks 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,
producesandconsumeson a mapping declare what an endpoint supports.
تفاصيل المخطط المبدئي
عرض عملي
@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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.