What is PUT used for?
PUT is an HTTP method used to fully update (replace) a resource on the server.
In simple terms: PUT is needed to replace existing data with new data entirely.
The main purpose of PUT
PUT is used when you need to:
- update an existing resource
- replace its current state with a new one
- save data at a specific address (URL)
The typical meaning of PUT:
"Here is new data, make the resource look exactly like this"
How PUT works
- The client sends an HTTP request with the PUT method
- The request body carries all of the resource's data
- The server:
- finds the resource by its URL
- fully replaces its content
- The server returns an HTTP response
If some field is missing from the PUT request, it may be removed or reset.
Where data is sent with PUT
Data is sent:
- in the request body
- usually as JSON or XML
An example of what the request means:
json
{
"id": 123,
"name": "Alice",
"email": "alice@example.com"
}A key property of PUT
Idempotency
PUT is an idempotent method:
- send PUT once, and the resource is updated
- send the same PUT 10 times, and the result is the same
This is a key difference from POST.
PUT vs POST (short and clear)
- POST
- create a resource
- the action can repeat with a different result
- PUT
- update (or replace) a resource
- a repeated request gives the same result
A way to remember it:
- POST - "create"
- PUT - "replace"
Real-life example
PUT is like:
- replacing a form entirely with a new version
- rewriting a document completely
- saving a file over the old one
You are not fixing individual lines, you are changing everything at once.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.