💡 If you like this website, please share it with your friends and network! 🚀
Back to All Questions
Question 8 of 100
Basic API Testing
Beginner

Q8: What is the Difference Between PUT and PATCH?

✂️Core Concept

What is the Difference Between PUT and PATCH?

Key Takeaways & Architecture Summary

  • PUT replaces the entire resource; missing properties are nullified or set to defaults.
  • PATCH applies partial updates, modifying only the fields explicitly provided.
  • PUT is idempotent by design; PATCH is typically non-idempotent.

Direct Answer Summary

PUT is designed for full resource replacement. If you submit a PUT request with only one field, the remaining fields of the resource are typically erased or reset to defaults. PATCH is designed for delta updates, modifying only the specific properties included in the request body while leaving other resource properties untouched.

⚠️ Senior Engineering Warning (Red Flag)

Never use PUT when you only want to change a single field like a user's email. Using PUT requires you to fetch the entire resource payload first and send it back; otherwise, you will accidentally clear out the missing fields.

💡 STAR Architectural Explanation & Pro Tip

PATCH requests are highly efficient because they save network bandwidth, especially when dealing with massive database records. However, they can be more complex to implement securely on the backend.

RestAssuredTest.java
Rest-Assured + Java
// Original user: { name: "John", status: "active", age: 30 }

// PUT request payload (Overwrites all):
// PUT /users/1 -> { name: "Jane" } -> User becomes { name: "Jane", status: null, age: null }

// PATCH request payload (Updates delta):
// PATCH /users/1 -> { name: "Jane" } -> User remains { name: "Jane", status: "active", age: 30 }