Posts: 132
Threads: 24
Joined: Jan 2016
Reputation:
8
Assuming that PATCH makes it possible to update one attribute at a time while the PUT forces the update of the entire entity.
Is not more versatile the default Update route for Resource be a PATCH method? Why?
Posts: 1,321
Threads: 21
Joined: Jan 2014
Reputation:
70
It is my understanding that PATCH, while "more correct", is not used instead of POST because of the ACTION attribute of an HTML form. The only way to generate a PATCH would be through an AJAX request
Posts: 132
Threads: 24
Joined: Jan 2016
Reputation:
8
Explaning more...
If you have a "product" entity with the following attributes:
- id
- title
- short_description
- description
- price
- stock
- uri
- rate
- bla
Every time that you need to update it. The PUT "forces" you to send all the attributes because have the function of REPLACE the entire entity. Then, if you need update ONLY the price attribute, you need to send ALL the other attributes.
The PATCH method enables you to send ONLY the price attribute. It is more flexible, save bandwidth traffic data and processing.
I read the GitHub REST API docs and see that it uses PATCH. I did some research and thought, "Why is PUT the default update verb in CI?"... And here is the question...
This change is only in the HTTP verb of Update. With a HTML form request nothing changes, continues to be with POST.
* I thought, originally, in Portuguese, Hahah.