]> PATCH Method for HTTP Open Source Application Foundation
2064 Edgewood Dr. Palo Alto CA 94303 US lisa@osafoundation.org
jasnell@gmail.com http://www.snellspace.com
Applications Individual Submission I-D webdav http simple patch deltav delta instance Several applications extending HTTP require a feature to do partial resource modification. Existing HTTP functionality only allows a complete replacement of a document. This proposal adds a new HTTP method, PATCH, to modify an existing HTTP resource.
The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI. The set of changes is represented in a format called a "patch document" identified by a media type. PATCH is neither safe or idempotent as defined by Section 9.1. The difference between the PUT and PATCH requests is reflected in the way the server processes the enclosed entity to modify the resource identified by the Request-URI. In a PUT request, the enclosed entity is considered to be a modified version of the resource stored on the origin server and the client is requesting that stored version be replaced. With PATCH, however, the enclosed entity contains a set of instructions describing how a resource currently residing on the origin server should be modified to produce a new version. The changes described by the entity MAY result in the creation of one or more new resources on the server, however it is not intended that the body of the PATCH request be used as the content of such resources. The server MUST always apply the entire set of changes atomically and never provide (e.g. in response to a GET during this operation) a partially-modified representation. If the entire patch document cannot be successfully applied then the server MUST fail the entire request, applying none of the changes. The determination of what constitutes a successful PATCH can vary depending on the patch document and the type of resource being modified. The actual method for determining how to apply the patch document to the resource is defined entirely by the origin server. See Error Handling in section 2.2 for details on status codes and possible error conditions. If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields or the response uses the 209 Content Returned status code as defined in Section 4. The 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource. Collisions from multiple requests are more dangerous than PUT collisions, because a patch document that is not operating from a known base point may corrupt the resource. Clients wishing to apply a patch document to a known entity can first acquire the strong ETag of the resource to be modified, and use that Etag in the If-Match header on the PATCH request to verify that the resource is still unchanged. If a strong ETag is not available for a given resource, the client can use If-Unmodified-Since as a less-reliable safeguard. It is RECOMMENDED that Servers provide strong ETags for all resources for which PATCH is supported. If a PATCH request contains any entity-headers the server does not understand, the server MUST return a 501 (Not Implemented) response. A server that understands a particular entity-header can choose to ignore it; however, doing so can produce results that are unexpected or unintended by the client. All entity-headers contained in the request apply only to the contained patch document and MUST NOT be applied to the resource being modified. If the Request-URI identifies a resource with multiple alternate representations, the server can choose to respond in a variety of ways. For instance, the server can decide which representation to alter and might even be able to change them all consistently depending on the patch format. A particular patch document might be able to identify specific representations to modify or might be capable of describing changes to multiple representations. If the server cannot choose a representation, it can reject the request with an error or the server can choose to redirect the request (e.g. using 301 Moved Permanently or 302 Found), in which case the user agent makes its own decision regarding whether or not to proceed with the request. Clients are advised to take caution when sending multiple PATCH requests, or sequences of requests that include PATCH, over a pipelined connection as there are no guarantees that pipelined requests will be processed by the server in the same order in which the client sends them. Such sequences of requests can be made safer by using conditional request mechanisms such as If-Match. See Section for additional details regarding pipelining and non-idempotent requests. There is no guarantee that a resource can be modified with PATCH. Further, it is expected that different patch document formats will be appropriate for different types of resources and that no single format will be appropriate for all types of resources. Therefore, there is no single default patch document format that implementations are required to support. Servers MUST ensure that a received patch document is appropriate for the type of resource identified by the Request-URI.
PATCH /file.txt HTTP/1.1 Host: www.example.com Content-type: application/example If-Match: "e0023aa4e" Content-Length: 100 [description of changes]
Successful PATCH response to existing text file HTTP/1.1 204 No Content ETag: "e0023aa4f" Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==
There are several known conditions under which a PATCH request can fail. Can be specified using a 400 Bad Request when the server finds that the patch document provided by the client was improperly formatted. The definition of badly formatted depends on the patch document chosen, but generally if the server finds it cannot handle the patch due to the serialization of the patch document, this response ought to be appropriate. Specified using a 415 Unsupported Media Type when the client uses a patch document format that the server does not support for the resource identified by the Request-URI. Such a response SHOULD include an Accept-Patch response header as described in Section 3.1 to notify the client what patch document formats are supported. Can be specified with a 422 Unprocessable Entity when the server understands the patch document and the syntax of the patch document appears valid, but the server is incapable of processing the request. There are a number of situations that could lead to such a result, for example: The client attempted to apply a patch document to an empty resource, but the patch document chosen cannot be applied to an empty resource. The client attempted to apply a structural modification and the structures assumed to exist did not exist (e.g. a patch which specifies changing element 'foo' to element 'bar' but element 'foo' doesn't exist). The client attempted to modify a resource in a way that would cause the resource to become invalid. For instance, a modification to a well-formed XML document that would cause it to no longer be well-formed. The client attempted to modify a resource that has multiple representations but the server was unable to choose which representation to modify. Specified with a 412 Precondition Failed when a client uses either the If-Match or If-Unmodified-Since request headers and attempts to apply a patch document to a resource whose state has changed since the patch was created. If the server detects a possible conflicting modification and neither the If-Match or If-Unmodified-Since request headers are used, the server can return a 409 Conflict response. When a server receives multiple concurrent requests to modify a resource, those requests SHOULD be queued and processed in the order in which they are received. If a server is incapable of queuing concurrent requests, all subsequent requests SHOULD be rejected until the first modification request is complete. Other HTTP status codes can also be used under the appropriate circumstances. The entity body of error responses SHOULD contain enough information to communicate the nature of the error to the client. The content-type of the response entity can vary across implementations.
[request] OPTIONS /example/buddies.xml HTTP/1.1 Host: www.example.com [response] HTTP/1.1 200 OK Allow: GET, PUT, POST, OPTIONS, HEAD, DELETE, PATCH Accept-Patch: application/example, text/example
The 209 "Content Returned" status code can be used to indicate that a response is equivalent to what would have been returned with a 200 status code response to a GET sent to the URI immediately following the successful completion of the request.
Header field name: Accept-Patch Applicable Protocol: HTTP Status: standard Author/Change controller: IETF Specification document: this specification
This specification defines the 209 Content Returned status code (Section 3) to be updated in the registry at <http://www.iana.org/assignments/http-status-codes>.
&rfc2119; &rfc2616; &rfc3864; &rfc4918;
The RFC Editor should remove this section and the Changes section.
There are several outstanding issues with the Prefer section: Should the Prefer section be separated out into a separate I-D? We need to determine how new preference codes are created/registered Are warn-codes ok or do we need a new response header?