HTTP PATCH Request Method

The HTTP PATCH method one of nine common Hypertext Transfer Protocol (HTTP) request methods used to partially modify an existing resource. The main difference from the HTTP PUT method is that the HTTP PATCH method performs partial modification of the resource, while the HTTP PUT method completely replaces the resource. Unlike HTTP GET and HEAD request methods, the PATCH method may change the server state.

What is HTTP PATCH Request Method?

The HTTP PATCH request method is a relatively new verb (RFC introduced in March 2010) that addresses the issue of “patching” or modifying existing resources. Before the PATCH method, you must use an HTTP POST request to update an existing resource.

The following example demonstrates sending a PATCH request to the server:

HTTP PATCH Request Example Run Request
PATCH /echo/patch/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 85

{PATCH DATA}

Can I send data to the server using the HTTP PATCH request method?

Yes, you can send data to the server in the body of an HTTP PATCH message. The type and size of data are not limited. But you must specify the data type in the Content-Type header and the data size in the Content-Length header. You can also send data to the server using URL parameters as for HTTP GET requests. In this case, you are limited to the maximum size of the URL, which is about 2000 characters (depends on the browser).

HTTP PATCH Method Specification

The PATCH method is not idempotent, which means that sending an identical PATCH request multiple times can further affect the state of the server or cause additional side effects.

Safe No
Idempotent No
Cacheable No
Can have a body Yes

HTTP PATCH VS PUT

The main difference between the PATCH and PUT request methods is how the server processes the data in the body of the PATCH request message.When a PUT request is made, the data in the body of the PUT message is treated as a new version of the existing resource, and the client requests a complete replacement. Unlike the PUT method, the PATCH method must contain data and a set of instructions describing how to modify the resource.

With an HTTP PATCH request, you don't need to send the full representation of the data to the server, instead, you only send the changed fields along with the names of those fields. For large objects, this can significantly reduce the amount of data sent to the server and reduce the processing time of such requests.

The second difference between the HTTP PATCH and PUT methods is that the PUT method is idempotent and the PATCH method is non-idempotent. The idempotent method means that multiple identical PUT requests will always give the same result on the server. On the other hand, multiple identical HTTP PATCH requests can additionally affect server state and have additional side effects.

See also

Updated: Viewed: 11520 times