What HTTP response code should be returned when the restriction fails?

We have two objects named Track and Walkthru . They are connected to each other through TrackWalkthruAssociation . If a Track and Walkthru are connected to each other (i.e. there is an instance of TrackWalkthruAssociation linking them together), none of them can be deleted if the TrackWalkthruAssociation instance that links them together is deleted first .

So send DELETE to /tracks/1 or /walkthrus/1 , for example, when an association exists, the failure should fail. What is the appropriate HTTP response code for? I do not want to return 500 because this is not an unexpected condition.

+6
source share
1 answer

Guess it's all right: 409 ("Conflict").

The 409 error response tells the client that they tried to put the REST API resources in an impossible or inconsistent state.

In the event that you delete any related resources before the link itself, you put the resources in an impossible state.

For more information and recommendations, see the RESTful Web API or the REST API Design Guide

+7
source

Source: https://habr.com/ru/post/977148/


All Articles