Sobes.tech
Junior

What is PATCH?

sobes.tech AI

Answer from AI

PATCH is an HTTP method used for partial modification of a resource. Unlike PUT, which replaces the entire resource, PATCH applies a set of changes to an existing resource.

Main characteristics:

  • Partial update: Changes only the specified fields of the resource.
  • Non-idempotent (usually): Repeated PATCH calls with the same parameters may lead to different results, depending on how the server interprets the set of changes.
  • Request body: Contains instructions for modifying the resource. The format of the request body is determined by the server and can be, for example, JSON Patch or Merge Patch.

Example of using JSON Patch:

[
    { "op": "replace", "path": "/title", "value": "New Title" },
  { "op": "add", "path": "/tags/0", "value": "new tag" },
  { "op": "remove", "path": "/comments/1" }
]