0

Let's say an API has the method DELETE for the endpoint /authors/:id, which also deletes all posts by said author.

I understand that, when an author is deleted from the database, all GET requests to /authors/:id/posts should respond with 410 GONE, indicating that said resource is no longer available.

How should the API understand that the resource used to exist but no longer does? After all, the query SELECT * FROM posts WHERE author_id = id; is empty.

The only "solution" I thought of was to not delete the posts, but check the existence of the author in the database and act accordingly.

  • You can delete the posts but don't delete the Author just add a column named ``IsDeleted`` to Author table and check if IsDeleted=true then it's Gone. – sa-es-ir Apr 13 '22 at 14:21

1 Answers1

0

In most business applications, you don't really want to delete records during the normal flow of operation, especially if you then have to cascade those deletes.

For instance, in a finance application, when a customer stops doing business with you, you don't want to delete that customer record and all the sales in the past - you want to set a flag saying "this customer is no longer active".

That's often referred to as a soft delete.

Your REST API can interpret the deleted status to issue the correct status code (GONE, rather than NOT FOUND)

Neville Kuyt
  • 29,247
  • 1
  • 37
  • 52