Middle
What HTTP methods do you know? How does PUT differ from PATCH?
sobes.tech AI
Answer from AI
Main HTTP methods:
- GET — retrieve data from the server.
- POST — create a new resource.
- PUT — replace the entire resource.
- PATCH — partially update the resource.
- DELETE — delete the resource.
- OPTIONS — find out supported methods.
Difference between PUT and PATCH:
- PUT replaces the entire resource. If some fields are missing in the request body, they will be deleted or reset.
- PATCH updates only the specified fields, leaving others unchanged.
Example:
PUT /users/1
{
"name": "Ivan",
"age": 30
}
Replaces the entire user object with id=1.
PATCH /users/1
{
"age": 31
}
Updates only the age field, other fields remain unchanged.