PUT replaces the entire resource at the given URL with the data sent in the request. It is used for full replacement of a resource.
Click to reveal answer
beginner
When should you use PUT instead of PATCH?
Use PUT when you want to replace the whole resource. Use PATCH when you want to update only parts of the resource.
Click to reveal answer
intermediate
If a resource does not exist, what can a PUT request do?
PUT can create the resource at the specified URL if it does not already exist.
Click to reveal answer
intermediate
What is the difference between PUT and POST in REST APIs?
PUT is idempotent and replaces a resource at a known URL. POST is not idempotent and is used to create a resource or trigger actions, often at a server-defined URL.
Click to reveal answer
intermediate
Example: What happens if you send a PUT request with partial data for a resource?
The resource will be replaced entirely with the partial data, potentially losing any fields not included in the request.
Click to reveal answer
What does a PUT request typically do in REST APIs?
AReplace the entire resource at the URL
BUpdate only part of the resource
CRetrieve data from the server
DDelete the resource
✗ Incorrect
PUT replaces the entire resource at the specified URL with the data sent.
Which HTTP method is idempotent and used for full replacement?
APOST
BPUT
CPATCH
DGET
✗ Incorrect
PUT is idempotent and replaces the full resource.
If a resource does not exist, what can a PUT request do?
ACreate the resource
BDelete another resource
CDo nothing
DReturn an error
✗ Incorrect
PUT can create the resource at the given URL if it does not exist.
What happens if you send partial data in a PUT request?
AThe request fails
BOnly the partial data is updated
CThe server merges the data automatically
DThe entire resource is replaced with the partial data
✗ Incorrect
PUT replaces the whole resource, so partial data will overwrite missing fields.
Which method is better for updating only some fields of a resource?
APUT
BPOST
CPATCH
DDELETE
✗ Incorrect
PATCH is designed for partial updates of a resource.
Explain how the PUT method works for full replacement in REST APIs.
Think about replacing a whole file instead of editing parts.
You got /4 concepts.
Describe the difference between PUT and PATCH methods.
Compare replacing a whole document vs. editing a paragraph.
You got /4 concepts.
Practice
(1/5)
1. What does the HTTP PUT method do when used on a REST API resource URL?
easy
A. Retrieves the resource data from the URL
B. Partially updates the resource fields at the URL
C. Fully replaces the resource at the URL with the provided data
D. Deletes the resource at the URL
Solution
Step 1: Understand PUT method purpose
PUT is designed to replace the entire resource at the given URL with the data sent in the request.
Step 2: Compare with other methods
Unlike PATCH which updates partially, PUT replaces fully. GET retrieves, DELETE removes.
Final Answer:
Fully replaces the resource at the URL with the provided data -> Option C
Quick Check:
PUT = full replacement [OK]
Hint: PUT replaces entire resource, not partial update [OK]
Common Mistakes:
Confusing PUT with PATCH partial update
Thinking PUT deletes resource
Assuming PUT only retrieves data
2. Which of the following is the correct HTTP method and usage to fully replace a resource at URL /users/123 with new data in JSON format?
easy
A. POST /users/123 with JSON body
B. PUT /users/123 with JSON body
C. PATCH /users/123 with JSON body
D. GET /users/123 with JSON body
Solution
Step 1: Identify method for full replacement
PUT is the HTTP method used to fully replace a resource at a specific URL.
Step 2: Match method with URL and body
PUT /users/123 with JSON body replaces the user data fully. POST is for creation, PATCH partial update, GET retrieves.
Final Answer:
PUT /users/123 with JSON body -> Option B
Quick Check:
PUT + URL + JSON = full replace [OK]
Hint: Use PUT with URL and full JSON body to replace resource [OK]
Common Mistakes:
Using POST instead of PUT for replacement
Using PATCH for full replacement
Sending body with GET request
3. 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"}
medium
A. {"name": "Bob"}
B. {"name": "Bob", "age": 30}
C. {"age": 30}
D. Resource deleted
Solution
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.
Step 2: Apply replacement to given data
Original data had name and age, but PUT body only has name "Bob", so age is removed.
Final Answer:
{"name": "Bob"} -> Option A
Quick Check:
PUT replaces all fields, missing fields removed [OK]
Hint: PUT replaces all fields; missing fields are removed [OK]
Common Mistakes:
Assuming PUT merges fields like PATCH
Expecting old fields to remain if not sent
Thinking PUT deletes resource
4. You wrote this PUT request to update a resource:
PUT /items/10 {"price": 100}
But after sending, the resource lost all other fields except price. How can you fix this to keep other fields intact?
medium
A. Use GET method instead
B. Add missing fields to the PUT JSON body
C. Send an empty body with PUT
D. Change PUT to PATCH to update partially
Solution
Step 1: Identify cause of lost fields
PUT replaces the entire resource, so missing fields in body are removed.
Step 2: Choose method to update partially
PATCH updates only specified fields, keeping others intact.
Final Answer:
Change PUT to PATCH to update partially -> Option D
Quick Check:
PATCH = partial update, keeps other fields [OK]
Hint: Use PATCH for partial update, PUT replaces all [OK]
Common Mistakes:
Trying to fix by adding missing fields manually
Sending empty body with PUT
Using GET to update resource
5. You want to update a user resource at /users/77 with new data {"name": "Eve", "age": 28}. The resource may or may not exist. Which is the best approach using PUT to ensure the resource is created if missing or fully replaced if exists?
hard
A. Send a PUT request with full user data to /users/77
B. Send a POST request to /users with partial data
C. Send a PATCH request to /users/77 with partial data
D. Send a GET request to /users/77 before updating
Solution
Step 1: Understand PUT behavior for create or replace
PUT can create the resource if it does not exist, or fully replace it if it does.
Step 2: Apply PUT with full data to target URL
Sending PUT with full user data to /users/77 ensures creation or full replacement.
Final Answer:
Send a PUT request with full user data to /users/77 -> Option A
Quick Check:
PUT = create or replace resource fully [OK]
Hint: PUT creates or replaces resource at URL with full data [OK]
Common Mistakes:
Using POST which creates new resource with new ID
Using PATCH which only updates existing resource partially
Using GET before update unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.