简体   繁体   中英

REST API: Delete operation affecting other objects

I have a question about REST API architecture. I plan to provide access for GET/POST/UPDATE/DELETE of objects of this type (yes, it is 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).

Is there a standard approach to inform user of my API about changes in affected objects?

PS One of my clients is using ExtJS. I think it will require some adjustment.

The propert HTTP status code is 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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