Bird
0
0

Given a REST API with a user resource at /users/42 initially having data {"name": "Alice", "age": 30}, what will be the resource data after this PUT request?

medium📝 Predict Output Q13 of 15
Rest API - HTTP Methods
Given a REST API with a user resource at /users/42 initially having data {"name": "Alice", "age": 30}, what will be the resource data after this PUT request?
PUT /users/42
{"name": "Bob"}
A{"name": "Bob"}
B{"name": "Bob", "age": 30}
C{"age": 30}
DResource deleted
Step-by-Step Solution
Solution:
  1. Step 1: Understand PUT replaces entire resource

    The PUT request replaces the whole resource data with the new JSON body, removing any fields not included.
  2. Step 2: Apply replacement to given data

    Original data had name and age, but PUT body only has name "Bob", so age is removed.
  3. Final Answer:

    {"name": "Bob"} -> Option A
  4. Quick Check:

    PUT replaces all fields, missing fields removed [OK]
Quick Trick: PUT replaces all fields; missing fields are removed [OK]
Common Mistakes:
MISTAKES
  • Assuming PUT merges fields like PATCH
  • Expecting old fields to remain if not sent
  • Thinking PUT deletes resource

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes