I'll describe my problem with a simple example, I have 2 tables (X
& Y
):
Table X Table Y
------------------ ----------
| id | Y_id | | id |
------------------ ----------
My API route will delete a row from table Y
but what if this row is being used by table X
, so for example this case:
Table X Table Y
------------------ ----------
| id | Y_id | | id |
------------------ ----------
| 1 | 1 | | 1 |
------------------ ----------
If I request to delete the row with id 1
from table Y
I will reject this request because the entry is being used in table X
, what should be the response HTTP status code in this scenario?
https://greenbytes.de/tech/webdav/rfc7231.html#status.409:
6.5.8. 409 Conflict
The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request. The server SHOULD generate a payload that includes enough information for a user to recognize the source of the conflict.
Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being used and the representation being PUT included changes to a resource that conflict with those made by an earlier (third-party) request, the origin server might use a 409 response to indicate that it can't complete the request. In this case, the response representation would likely contain information useful for merging the differences based on the revision history.