Sobes.tech
Middle

What methods can you name in REST API? How does PUT differ from PATCH?

sobes.tech AI

Answer from AI

The main HTTP methods in REST API: GET (retrieve data), POST (create a resource), PUT (full update of a resource), PATCH (partial update of a resource), DELETE (delete a resource).

Difference between PUT and PATCH:

  • PUT replaces the entire resource. If a field is not specified in the request, it will be deleted or reset to its default value.
  • PATCH updates only the specified fields, leaving others unchanged.

Example:

PUT /users/123
{
  "name": "Ivan",
  "age": 30
}

Will replace the entire user profile; if, for example, the "email" field is not specified, it will be deleted.

PATCH /users/123
{
  "age": 31
}

Will only update the age, leaving other data unchanged.

What methods can you name in REST API? How does PUT… - sobes.tech