Senior
What HTTP methods do you know? How do PUT and PATCH differ?
sobes.tech AI
Answer from AI
Main HTTP methods:
- GET — retrieve a resource
- POST — create a new resource
- PUT — replace the entire resource
- PATCH — partially update the resource
- DELETE — delete the resource
- HEAD — get resource headers
- OPTIONS — find out supported methods
Difference between PUT and PATCH:
- PUT replaces the entire resource with a new representation. If fields are missing in the request, they will be deleted or reset.
- PATCH modifies only the specified fields, leaving others unchanged.
Example:
PUT /users/123
{
"name": "Ivan",
"age": 30
}
Replaces the entire user profile.
PATCH /users/123
{
"age": 31
}
Only updates the age, other data remains unchanged.