Update: PUT vs PATCH
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
choose and implement the right update style.
Planned topics
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.
Draft outline details
Demonstration
if (req.name() != null) category.setName(req.name());
if (req.description() != null) category.setDescription(req.description());Check your understanding
What should a PATCH do with a field the client did not send?
Show answer
Leave it unchanged.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.