This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8747|Reply: 0

The difference between a restful patch and a put request

[Copy link]
Posted on 9/28/2020 10:38:45 PM | | |
I saw that laravel uses Route::resource to generate a route for a restful architecture, and the update in it uses patch requests, while some places say to use put, so I checked it

  • put to update all resources
  • patch method is used to update local resources

Let's say we have a UserInfo with 10 fields like userId, userName, userGender, etc. But your editing function can only modify the userName in a special page due to needs, how to update at this time?

People usually pass a full userInfo object containing the modified userName to the backend for a full update. But if you think about it, this approach feels a bit two-pronged and a real waste of bandwidth (purely technically, if you don't care about bandwidth, you're a local tyrant).

Thus, patch was born, which only sends a userName to the specified resource, indicating that the request is a partial update, and the backend only updates the received fields.

Theoretically, if you use put but do not provide a complete UserInfo, then the missing fields should be cleared

PUT:Used to create a resource with a known URL, or pairKnown resources are fully replaced。 It is generally used to update a known resource, unless you know the URL of the object you want to create before creating it.

POST:to create a sub-resource,If it is not idempotent, multiple executions will result in multiple identical resources being created。 (Powers:In programming, an idempotent operation is characterized by the fact that its arbitrary multiple executions have the same effect as a single execution。 )

PATCH:It is a complement to the PUT method and is used to perform on known resourcesPartial updates




Previous:This detailed explanation of Javascript
Next:C# imports from Excel tables (100,000 data) into the database
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com