Soft Delete Resources


#1

Hello, guys! There is common practice to delete resources to trash bin or archive on delete (to have an ability to restore them) and have additional force delete command to remove them completely from the database.

Imagine the situation when you want to delete task from the project management system, but it should be only marked as deleted, but kept as archived. And need an ability to restore it with the same id as it was before.

On DELETE /tasks/1 controller will execute soft-delete command and resource will update database column archived_at with current DateTime. Then resource will be excluded from all GET /tasks responses.

Why I’ve chosen to use DELETE method instead of updating status: archived field of the resource? Because there are a lot of cases when user shouldn’t know about resource is soft-deleted and will lose access to this record completely right after it’s soft-deletion. Only privileged users will have such permissions.

There are 2 questions which I’m trying to find answer to:

  1. How we could restore soft-deleted resource.
  2. How we could force delete resource.

This thread is related to “Should you return all resources by default (when no filter specified)” but not duplicates it, because it covers soft-delete, restore soft-delete and force-delete processes and not filtering strategy.