The PATCH method is newly introduced and is a supplement to the PUT method, which is used to perform local updates to known resources.
question:
What is a partial update?
For example, I can update it on a restful editing page, and use put and PATCH to succeed, but I don’t quite understand what local is.
patch
How should we understand the method used to update local resources?
Suppose we have oneUserInfo
, there isuserId
, userName
, userGender
10 fields. However, your editing function can only be modified in a special page due to requirements.userName
, how to update this time?
People usually (save trouble) include one after the modificationuserName
CompleteuserInfo
The object is passed to the backend for complete updates. But if you think about it carefully, this approach feels a bit 2, and it really wastes bandwidth (only technically, if you don’t care about bandwidth, that’s your rich man).
thenpatch
Birth, only oneuserName
Go to the specified resource, which means that the request is a local update, and the backend only updates the received fields.
andput
Although it is also an update resource, the front-end must provide a complete resource object. In theory, if you use itput
, but no completeUserInfo
, then the missing fields should be cleared
Replenish:
Finally, I would like to add one more sentence,restful
It is just a standard. The standard means that if everyone acts according to this, the communication cost will be very low and the development efficiency will be high. But it is not forced (no one can force it), so you said that the method name in your program is fromput
Change topatch
There is no impact, that is natural, because your backend program does not handle the two methods differently according to the standards, and her performance is naturally the same
To add, an important difference between PATCH and PUT properties is that PUT is idempotent, while PATCH is not idempotent.
Impotence is a mathematical and computer science concept. In the computer category, it means that the effect of an operation to perform any time on the system is the same as that of once.
The definition of idempotence in the HTTP/1.1 specification is:
Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request.
For example: The POST method is not idempotent. If it is repeatedly executed multiple times, a new resource will be created. If the request timed out, you need to answer this question: Has the resource been created on the server side? Can I try again or check the resource list? And for the idempotent method, we can request it multiple times with confidence.
/q/1010000005685904/