RESTful, talking about the patch method of HTTP

Source: Internet
Author: User
Tags rfc jboss

At the earliest, we only need GET and post methods, the introduction of post method is only to eliminate the URL too long, parameter hiding, uploading the file problem, completely and semantically irrelevant. After touching the RESTful, we began to think about the different semantics of GET and POST, and it was necessary to dig out all the method implemented by HTTP method,http/1.1, see RFC 2616, with these:

OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT

The specification is so defined, which depends on how much the container implements, such as the Servlet API in Tomcat 7 implements the

Dooptions, Doget, Dohead, DoPost, DoPut, DoDelete, Dotrace is a doconnect.

The PATCH method we're talking about here is mentioned in both Servlet 3.0 and current Tomcat 7, which is not yet implemented.

It's no wonder that PATCH became a formal method in March 2010, see RFC 5789. When there is no PATCH, we use the PUT method to update the operation. So what's the difference between PATCH and PUT?

The same can be understood in terms of semantics, with two contrasting aspects:

1. Operations on an existing resource:

Patches are used to update part of a resource's content, such as updating a field. Specifically, for example, only the phone number field for updating user information

Instead, PUT is used to update a more complete content of a resource, such as when a user wants to refill a full form to update all the information, and the background processing update may just keep the internal record ID intact.

2. When a resource does not exist:

Lenovo to version control patches is a modification of the original content, and may result in a new version. For example, when a resource does not exist, patches may create a new resource, in the sense of a saveorupdate operation.

This article original link http://unmi.cc/restful-http-patch-method/, from Yehuang Unmi Blog

PUT only updates an existing resource, so it is an update operation

See when should we use the PATCH HTTP method? In the RESTful CookBook

The HTTP methods PATCH can used to update the partial resources. For instance if you have need to update one field of the resource, putting a complete resource representation might be Cumbersome and utilizes more bandwidth

Patch/user/jthijssen http/1.1<user>    <firstname>Joshua</firstname></user>

Also, the PUT method is idempotent. Putting the same data multiple times to the same resource, should no result in different resources, while POSTing to the Same resource can result creation of multiple resources.

-See more at:http://restcookbook.com/http%20methods/patch/#sthash. Gygm7j3q.dpuf

The difference between PATCH and PUT is more detailed in RFC 5789.

Look again at the current who implemented the patch method, who has not implemented the patch method

1. Apache httpcomponents HttpClient version 4.2 or later support PATCH
2. Currently JDK7 HttpURLConnection not implemented PATCH
3. TOMCAT 7 is not
4. Playframework 2 also does not support
5. Spring 3.2 begins to support PATCH methods, but the container to deploy is selected
6. JBoss Netty Support PATCH, visible: http://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/codec/http/class-use/ Httpmethod.html

In short, there are few containers that implement the PATCH method.

Reference: 1. List of HTTP methods (verbs)
2. Method Definitions
3. RFC 5789-patch Method for HTTP
4. RFC 2616
5. Standard Methods-restful API Design

This article links http://unmi.cc/restful-http-patch-method/, from Yehuang Unmi Blog

RESTful, talking about the patch method of HTTP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.