简体   繁体   English

REST API:删除操作会影响其他对象

[英]REST API: Delete operation affecting other objects

I have a question about REST API architecture. 我有一个关于REST API架构的问题。 I plan to provide access for GET/POST/UPDATE/DELETE of objects of this type (yes, it is Django): 我计划为这种类型的对象的GET / POST / UPDATE / DELETE提供访问权限(是的,它是Django):

class Synonym(models.Model):
    name = models.CharField(max_length=64)
    parent = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)

As you can see, when some object (for example, /synonyms/3) is deleted, all it's childs will have their parent_id set to None (null). 如您所见,当删除某个对象(例如/ synonyms / 3)时,其所有子对象的parent_id都将设置为None(空)。

Is there a standard approach to inform user of my API about changes in affected objects? 是否有一种标准方法来通知我的API用户有关受影响对象的更改?

PS One of my clients is using ExtJS. PS我的一位客户正在使用ExtJS。 I think it will require some adjustment. 我认为这将需要一些调整。

The propert HTTP status code is 410 GONE . 属性HTTP状态代码为410 GONE

Indicates that the resource requested is no longer available and will not be available again. 指示请求的资源不再可用,并且将不再可用。 This should be used when a resource has been intentionally removed and the resource should be purged. 当故意删除资源并清除该资源时,应使用此方法。 Upon receiving a 410 status code, the client should not request the resource again in the future. 收到410状态代码后,客户端以后不应再请求资源。

There is no special way to informa about the deletion having affected children of the deleted resource. 没有特别的方法可以通知有关已影响已删除资源的子项的删除。 You should document your resources and clearly state that some resource can an will only exist as children of a parent. 您应该记录您的资源,并明确声明某些资源只能作为父母的孩子存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM