是否可以使用补丁进行全面更新而不是放?(Is it okay to use patch for full update instead of put?)

系统教程 行业动态 更新时间:2024-06-14 16:59:22
是否可以使用补丁进行全面更新而不是放?(Is it okay to use patch for full update instead of put?)

我正在使用Django和DRF进行API。 假设我有一个包含三个字段的对象(名称,密码,电子邮件)。 当用户想要同时更新他的姓名,密码和电子邮件时,我可以发送PATCH请求而不是PUT请求吗? 有什么垮台?

我觉得这比检查用户是否正在更新所有字段更方便,如果是,则使用PUT请求,但如果不是,则使用PATCH 。

检查对象是否存在已经在后端处理,并且在创建对象时,我使用CREATE / POST而不是PUT因为它对我来说更方便。

编辑:我正在使用AngularJS的PATCH : https ://docs.angularjs.org/api/ng/service/ $ http#patch将内容发送到后端,后端由DRF Viewset处理(处理PATCH请求)。

I am using Django and DRF for APIs. Suppose I have an object with three fields (name, password, email). When a user wants to update his name, password and email at the same time, is it okay for me to send a PATCH request instead of a PUT request? What are the downfalls?

I feel this is more convenient than checking if the user is updating all fields, and if he is, using a PUT request, but if he's not, using a PATCH.

Checking if the object exists is already taken care of in the backend, and when creating objects, I use CREATE / POST instead of PUT because it is more convenient for me.

Edit: I am using AngularJS's PATCH: https://docs.angularjs.org/api/ng/service/$http#patch to send content to the backend, which is handled by DRF Viewset (which handles PATCH requests).

最满意答案

使用PATCH是可以的。 但请注意,它不会检查必需的字段而不是PUT。

It's OK to use PATCH. However, note that it will not check for required fields as opposed to PUT.

更多推荐

本文发布于:2023-04-16 19:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c5b847c59064ca846c2de1765a33f40e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   进行全面   而不是   补丁   put

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!