Skip to main content

What is PATCH used for?

PATCH is an HTTP method used to partially update a resource on the server.

In simple terms: PATCH is needed to change only part of the data, not the whole object.


The main purpose of PATCH

PATCH is used when you need to:

  • change one or a few fields of a resource
  • leave the rest of the data untouched
  • perform a "targeted" update

The typical meaning of PATCH:

"Change these specific fields, leave everything else as is"


How PATCH works

  1. The client sends an HTTP request with the PATCH method
  2. The request body carries only the fields being changed
  3. The server:
  • finds the resource
  • updates only the specified fields
  1. The server returns an HTTP response

Where data is sent with PATCH

Data is sent:

  • in the request body
  • usually as JSON

An example of what the request means:

json
{ "email": "new_email@example.com" }

The rest of the resource's fields do not change.


PATCH vs PUT (very important)

This is a common interview question.

  • PUT
    • a full replacement of the resource
    • the whole object must be sent
    • a missing field may be removed
  • PATCH
    • a partial update
    • only the changed fields are sent
    • safer for small changes

A way to remember it:

  • PUT - "replace everything"
  • PATCH - "fix a piece"

Properties of PATCH

  • usually not idempotent (depends on the implementation)
  • not cached
  • used in REST APIs for updates

Real-life example

PATCH is like:

  • changing a phone number in a profile
  • fixing a typo in a text
  • updating one setting

You are not rewriting everything, you are changing only what's needed.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.