我正在使用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.
更多推荐
发布评论