What is PATCH?
The REST (Representational State Transfer) protocol was designed to standardize HTTP communication between clients and servers. REST is a system of rules and connectors all services must follow and use. If you’ve ever had to order a special dongle for that one piece of hardware without a USB connector, you understand the problem that REST solves.
REST APIs perform specific methods of data operations across HTTP:
- GET - This operation reads information from a record in the database.
- PUT- This operation changes a record’s information in the database.
- POST - This operation creates a new record in the database.
- PATCH - This operation updates an existing resource, but does not require sending the entire body with the request.
- DELETE - This operation removes a record from the database.
In this article we are focusing on the PATCH operation. What does PATCH do, and how is it different from POST and PUT? In the [words of the RFC2028 memo, "The PATCH method is similar to PUT except that the entity contains a list of differences between the original version of the resource identified by the Request-URI and the desired content of the resource after the PATCH action has been applied."
PATCH API Example
A PATCH request sends data to an API to update an existing resource. PATCH is like a single field in a contact form on a website. When you fill out a single field and hit Send, that data is put in the response body of the request and sent to the server. This may be JSON, XML, or query parameters.
A PATCH request might look like this: `PATCH https://www.abstractapi.com/users/{{userID}}`. This would send data to the `/users/{{userID}}` endpoint, and update that user's information.
A successful PATCH request should return a `2xx` status code, and PATCH requests should fail if invalid data is supplied in the [request](https://restfulapi.net/http-methods/).
What is the Difference between PUT, PATCH, and POST?
Maybe you looked at the list of operations above and wondered what the differences are between POST, PUT, and PATCH. We use them for different situations, depending on idempotency. If a request is idempotent, calling it once or several times successively has the same effect. If the request is non-idempotent, each successive request will act on the previous request, causing potential problems.
How is PATCH different from PUT?
The difference between PUT vs PATCH is that PUT is idempotent: calling it once or several times successively has the same effect, whereas successive identical PATCH requests may have additional effects, akin to placing an order several times.
How is PATCH Different from POST?
PATCH is used less frequently than POST. PATCH applies only partial modification to a resource, unlike POST and PUT, which modify the entire resource. PATCH is non-idempotent, while PUT is idempotent.
Using the `PATCH https://www.abstractapi.com/users/{{userID}}` example from above, if a user wanted to change their username, a POST or PUT request would send the entire user entity, while PATCH could send just the updated username.
Conclusion
Becoming confident in request methods is an important step in your programming journey. They might seem a little confusing in the beginning, but knowing when to use a POST, a PUT, or a PATCH will make you use resources more efficiently. You might not need to understand the deep mathematical complexities of idempotency, but it's important to know how you are modifying a record with POST, PUT, or PATCH.
Frequently Asked Questions
What is the PATCH method in a REST API?
PATCH is an HTTP method used to apply a partial update to an existing resource on a server. Instead of sending the complete resource, you send only the fields you want to change. RFC 2068 describes it as sending a list of differences between the current resource and the desired result.
How does the PATCH method work?
You send a PATCH request to the URL of a specific resource along with just the fields that need to change, such as PATCH https://www.abstractapi.com/users/{userID}. The server applies those changes to the existing record. A successful PATCH request returns a 2xx status code, and it fails when invalid data is supplied.
What is the difference between PATCH and PUT?
PATCH applies only a partial modification to a resource, while PUT replaces or changes the entire resource. The other key difference is idempotency: PUT is idempotent, so running it once or many times produces the same result, whereas PATCH is non-idempotent, meaning repeated identical requests can produce additional effects, similar to placing an order several times.
What is the difference between PATCH and POST?
POST creates new records, while PATCH modifies part of an existing one. POST and PUT operate on the complete resource, which makes them less efficient for small updates, whereas PATCH only changes the specific fields you send.
Is PATCH idempotent?
No, PATCH is non-idempotent. Sending the same PATCH request multiple times can produce additional effects beyond the first request, unlike PUT, which produces the same result no matter how many times it is sent.
When should you use the PATCH method?
Use PATCH when you only need to update part of a resource rather than replace the whole thing, such as changing a single username field on a user record. Sending only the modified fields makes it more efficient than methods that require the complete resource body.


