Skip to content
Ameen Abozaid
Planned lessonJNR-019-L03

Update: PUT vs PATCH

  • Lesson 3 of 8
  • Junior
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/5 replaces the whole item. The client sends every field.
  • PATCH /categories/5 changes only the fields sent.
  • A PUT is idempotent. Return 200 with the body or 204 without.
  • Danger: a PATCH that treats a missing field as null wipes 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

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

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.