Say I have the following relational structure of data (for examples sake):
A `post` which is a child of a `category`
This data can be accessed via these API endpoints:
GET /category/1
GET /category/1/post/1
GET /category/1/post/2
I have now decided that I want to use my API to delete category 1
so I run DELETE /category/1
.
However, category 1
has relational child post elements that can't exist without the category, would you expect this call to either fail and say you must first delete the child elements OR automatically recursively delete the child elements when you delete the category?
In RESTful APIs resources are typically deleted using the HTTP DELETE method. The resource that should be deleted is identified by the request URI.
A successful response of DELETE requests SHOULD be an HTTP response code 200 (OK) if the response includes an entity describing the status. The status should be 202 (Accepted) if the action has been queued.
Use the sObject Rows resource to delete records. Specify the record ID and use the DELETE method of the resource to delete a record.
Under REST architecture, the client and server can only interact in one way: The client sends a request to the server, then the server sends a response back to the client. Servers cannot make requests and clients cannot respond — all interactions are initiated by the client.
IMO this is more of a design decision and their really is no wrong way to do it. So it all depends on the requirements.
If you decide that deleting a category deletes all the child post elements, then you can do that in multiple way (ordered by my preference).
If you decide to not do the "cascade" delete for the child post, then your only option is to return an appropriate error message stating why the category cannot be deleted.
If you want you can make it more clear what the call to the web service does by doing something like this.
DELETE /category/1?includePost=true --> Deletes category #1 & all post under it.
DELETE /category/1 --> Delete category #1 or returns error if it can't delete it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With