Junior — Middle
Explain what the PATCH HTTP method is and in what situation it is used?
sobes.tech AI
Answer from AI
The HTTP PATCH method is used for partial updates of a resource on the server. Unlike PUT, which typically replaces the entire resource, PATCH allows sending only the fields or data that need to be changed.
It is used when small modifications are needed without sending the full representation of the resource, saving bandwidth and simplifying processing.
Example of usage:
If a user has a profile with several fields and only the email address needs to be updated, the PATCH request can contain only this field.
PATCH /users/123 HTTP/1.1
Content-Type: application/json
{
"email": "newemail@example.com"
}
The server will apply this change without affecting other user data.