The PUT Method: Replacing a Product

How an administrator replaces a product completely: a PUT request with the full data, code 200, and how PUT differs from PATCH.

About the product

Alex, QA Team Lead

Hi! Changing a price is clear. But what if you need to update the whole product: both the name and the price? Today we look at the second way to change a product — the PUT method — and compare it with PATCH.

Quick reference

The PUT method

PUT /api/v1/products/5 means “replace completely”. The request body has all the data of the object, and the server replaces the old data with it.

Code 200 OK

A success response. The server returns the whole product in the body, already with the new data. The id itself doesn’t change on replacement.

PUT and PATCH

PUT sends all fields, even if only one changed. PATCH sends only the fields that change.

What a tester checks

The response code is 200, and the body has the product with the new data. In the database the name and the price are updated, and the id is the same. The new data is visible in the admin panel and in the catalogue.