API Methods Explained

HTTP Method: PUT

The PUT method updates existing data on the server. It replaces a resource with the new version sent in the request. Let’s explore how PUT works and how testers should validate it.

What Is the PUT Method?

PUT sends complete data to update a resource. The client passes a full replacement version of the item. Use PUT when you:

  • Update user profile details
  • Replace product information
  • Modify saved settings
  • Change order details

PUT requires the resource ID from the client. If the resource does not exist, some APIs may create it.

How PUT Request Works

PUT always includes data in the request body. The server reads it and updates the stored record. Below is the flow:

  • Client sends full updated data
  • Server validates input
  • Server updates the record
  • Server responds with success message

Example:

PUT /users/10 HTTP/1.1
Content-Type: application/json
{
"name": "Alex",
"email": "alex@example.com"
}
Server returns:
200 OK
Now the record uses only this new data.

Key Characteristics of PUT

PUT changes data, not creates new actions. It is idempotent by design.

  • Safe for repeat requests
  • Full resource replacement
  • Predictable update operation

Common response codes from API server for PUT request are:

  • 200 OK — Update succeeded
  • 204 No Content — Updated, no message needed
  • 404 Not Found — ID incorrect
  • 400 Bad Request — Validation failed

Multiple PUT calls to the same API endpoint gives the same result. This helps with stable automation.

PUT Testing Checklist

Strong validation keeps data safe. Here is what testers should check for a PUT request:

  • ID exists and is valid
  • Complete data fields passed
  • No partial update risk
  • Duplicate calls do not break records
  • Data replaced exactly as sent
  • Correct response codes
  • Old data removed if required
  • DB changes match request body

PUT must not mix old and new data. Test this with careful inspection.

Real-World Example

You update your address in a food app.
The app replaces your old details with new data.

PUT updates the entire address record.
Every delivery uses fresh and correct information.

Summary: When to Use PUT?

Use PUT when the request updates a full resource. Do not use PUT for partial updates. Quick rule: If you replace data → choose PUT.





Related topics