![]() |
Resource Routes - PUT vs PATCH - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: Resource Routes - PUT vs PATCH (/showthread.php?tid=68519) Pages:
1
2
|
Resource Routes - PUT vs PATCH - natanfelles - 07-20-2017 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? RE: Resource Routes - PUT vs PATCH - Narf - 07-21-2017 (07-20-2017, 06:15 PM)natanfelles Wrote: Assuming that PATCH makes it possible to update one attribute at a time Wrong assumption. You can update as many attributes as you want. RE: Resource Routes - PUT vs PATCH - natanfelles - 07-21-2017 (07-21-2017, 01:46 AM)Narf Wrote:(07-20-2017, 06:15 PM)natanfelles Wrote: Assuming that PATCH makes it possible to update one attribute at a time No. Yes, with PATCH you can update as many attributes as you need individually. But, as I understand it, the PUT is used to replace the entire entity. I believe that PATCH makes the application more flexible because it does not "force" the client to send all the attributes to be updated, but only what is necessary. I saw in most of the documentation recommending the use of PUT as the default for updating, but studying the difference between PUT and PATCH I had this doubt. Here are some opinions and examples to take into consideration: https://stackoverflow.com/questions/28459418/rest-api-put-vs-patch-with-real-life-examples RE: Resource Routes - PUT vs PATCH - skunkbad - 07-21-2017 (07-21-2017, 09:37 AM)natanfelles Wrote: I believe that PATCH makes the application more flexible... Flexible != Rigid REST API. If you want flexible, GET and POST all the way home. https://www.youtube.com/watch?v=WO23WBji_Z0 RE: Resource Routes - PUT vs PATCH - natanfelles - 07-22-2017 (07-21-2017, 04:37 PM)skunkbad Wrote:(07-21-2017, 09:37 AM)natanfelles Wrote: I believe that PATCH makes the application more flexible... Ok. Then is used PUT by default to the system be rigid. Now I think that I understand why this is the default verb in the Resource Routes. ![]() RE: Resource Routes - PUT vs PATCH - kilishan - 07-22-2017 I guess my knowledge was simply based on old practices. Reading back through RFC7231 and RFC5789 it appears you are correct. Quote:The difference between the PUT and PATCH requests is reflected in the To the best of my knowledge those are the two most current versions of the relevant RFCs. So, yes, PATCH should be the default. In the end, it doesn't really matter because it's all in how you code your application to behave, anyway ![]() RE: Resource Routes - PUT vs PATCH - ciadmin - 07-22-2017 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 RE: Resource Routes - PUT vs PATCH - natanfelles - 07-22-2017 (07-22-2017, 09:11 PM)ciadmin Wrote: 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 Yes. But I'm referring to Resource Routes. RE: Resource Routes - PUT vs PATCH - ciadmin - 07-22-2017 (07-22-2017, 09:21 PM)natanfelles Wrote:(07-22-2017, 09:11 PM)ciadmin Wrote: 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 Good point ![]() RE: Resource Routes - PUT vs PATCH - natanfelles - 07-23-2017 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. |