Bird
0
0

A developer wrote this PUT request handler in a REST API:

medium📝 Debug Q6 of 15
Rest API - HTTP Methods
A developer wrote this PUT request handler in a REST API:
def put_user(user_id, data):
    user = get_user(user_id)
    user.update(data)
    save_user(user)

What is the main problem with this code regarding PUT semantics?
AIt does not save the user after update
BIt deletes the user before updating
CIt partially updates the user instead of fully replacing it
DIt uses the wrong HTTP method
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the update method usage

    Using user.update(data) merges new data into existing user, causing partial update.
  2. Step 2: Compare with PUT full replacement

    PUT requires replacing the entire resource, not merging fields.
  3. Final Answer:

    It partially updates the user instead of fully replacing it -> Option C
  4. Quick Check:

    PUT must fully replace resource, not partial update [OK]
Quick Trick: PUT replaces whole resource; update() merges partially [OK]
Common Mistakes:
  • Using partial update logic for PUT
  • Not replacing entire resource
  • Confusing PUT with PATCH

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes