REST API & HTTP Status Code

I have a bunch of PUT operations which execute actions on the input resource. Let's make an example: I have a payment operation in my API which state that a credit card must be charged by a specific Amount. In my code I first verify if there is sufficient credit on the card and then execute the operation. If there is'nt sufficient amount I simply return 400 but I am not sure it is correct.

Which is the correct HTTP Status Code in cases like this?

I can, of course send a response with HTTP 200 and attach a payload with further details explaining the error. I can also send back an HTTP 400 Bad Request or even better an HTTP 412 Precondition Failed .

Which is the correct code to send in the response in scenario like this where the validation failed? Is there any resource that I can read to understand the rationale behind HTTP Status Codes and HTTP Verbs?

链接地址: http://www.djcxy.com/p/45406.html

上一篇: “已存在”状态码

下一篇: REST API和HTTP状态码