What's the right HTTP status code for a respon

2019-04-18 15:56发布

问题:

What would be the right response I should give to the users when they try to DELETE an entity on a datasource sitting behind a rest/odata api, and the operation cannot be performed due to a foreign key constrain? Is it a bad request? A not acceptable? A server-side error (>=500)?

回答1:

Just found this website that says that '409 Conflict' should be used when 'the request could not be completed due to a conflict with the current state of the resource' and 'where it is expected that the user might be able to resolve the conflict and resubmit the request', then it gives an example when 'cascade-delete is not supported' which kinda resembles my scenario..

http://www.restapitutorial.com/httpstatuscodes.html