Java code for PATCH Request ExampleThis Java code snippet was generated automatically for the PATCH Request example.
<< Back to the PATCH Request example
What is HTTP?
HTTP is an application layer data transfer protocol widely used to transfer data between HTTP clients (browsers, mobile apps, etc.) and servers. HTTP defines various request methods that indicate the desired action (add, update, delete, etc.) for a given resource. Although request method names can be nouns, these methods are sometimes referred to as HTTP verbs. Each request method implements its own semantics and performs a specific action, but all methods can be combined into groups with common properties. For example, a group can determine if the methods in the group are safe or not.
What is the HTTP PATCH request method used for?
The HTTP PATCH request method is used to modify an existing resource on the server partially. The PATCH request method may or may not be idempotent, unlike HTTP PUT, which is always idempotent. An operation is considered idempotent if sending an identical PATCH request multiple times produces the same result as a single operation, does not affect the further state of the server, and does not cause additional side effects.
Can I send data with a PATCH request?
You can send data to the server in the body of an HTTP PATCH message the same way as the POST request. The type and size of data are not limited. The Content-Type request header must indicate the correct data type in the body of the PATCH message.
PATCH Request Example
The following is an example of sending a PATCH request to a ReqBin echo API endpoint:
What is the difference between the PATCH and PUT HTTP request methods?
The main difference between HTTP PATCH and PUT requests is how the server handles the resource specified in the Request-URI. When a PUT request is made, the request's data is treated as a modified version of the object stored on the origin server, and the client requests a full replacement. However, PATCH's request's data is treated as a partial object and contains instructions describing how PATCH should partially modify the resource stored on the origin server. The second difference is idempotency. HTTP PUT is idempotent because it always gives the same results after making multiple requests. On the other hand, the HTTP PATCH is generally considered non-idempotent. However, it can be idempotent depending on how the PATCH request will modify the object.