التحديث: PUT مقابل PATCH
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
choose and implement the right update style.
الموضوعات المخطط لها
PUT /categories/5replaces the whole item. The client sends every field.PATCH /categories/5changes only the fields sent.- A
PUTis idempotent. Return200with the body or204without. - Danger: a PATCH that treats a missing field as
nullwipes data. Missing means "leave unchanged". - Use optional fields in the patch DTO and apply only the ones present; verify the exact approach before recording.
تفاصيل المخطط المبدئي
عرض عملي
if (req.name() != null) category.setName(req.name());
if (req.description() != null) category.setDescription(req.description());اختبر فهمك
What should a PATCH do with a field the client did not send?
أظهر الإجابة
Leave it unchanged.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.