When would you use PATCH vs PUT?

Intermediate

Answer

PUT: Replaces the entire resource with the provided data. If you omit fields, they should be set to default/null values.

PATCH: Partial update of a resource. Only updates the fields provided in the request body.

Example:

PUT /users/123
{
  "name": "John Doe",
  "email": "john@example.com"
}
# Replaces entire user object

PATCH /users/123
{
  "email": "newemail@example.com"
}
# Only updates email field