Http status code for updates with conditions

Good morning:

I have a resource from my api that updates a record of my database if a condition is met, when it is met and the record is updated I return a HTTP status code 200, but I do not know what Http status code return when the condition is not met, since it can not be a 400 error, because the request is well formed

Thank you very much for the reply

Upvotes: 1

Views: 1342

Answers (1)

Julian Reschke
Julian Reschke

Reputation: 42017

You can use a 4xx even if the request is well-formed (what makes you think otherwise?):

The 4xx (Client Error) class of status code indicates that the client seems to have erred. Except when responding to a HEAD request, the server SHOULD send a representation containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents SHOULD display any included representation to the user.

(see https://greenbytes.de/tech/webdav/rfc7231.html#status.4xx)

Returning a 2xx when the request failed doesn't make any sense at all.

Upvotes: 2

Related Questions