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。
|