What happens when you call parseFoo("invalid data")? Does it return an error result (maybe null)? Or does it throw an exception? Many will take a near-religious position on whether one approach or the other is correct, but ultimately it's up to the API specification. I'd draw an analogy to calling a function parseFoo. If your spec doesn't make that accommodation, it would be a poor decision to return that response with a 200 code. JSON block with a, then it's a successful response.
If client asks for a seat on a plane that is booked full, that would be 200 and your "implementation" will dictate how to recognise/handle this (e.g. If there is a misconfiguration on the server that might be a 500. If for instance the client is asking for a file that isn't there, that would be more like a 404. Whether this applies to your case is up to you. To summarize: YES it is valid to send error messages (for non-technical issues) in your http response together with HTTP status 200.
wrong parameters, unexpected HTTP method.) Again, these all indicate technical errors, whereas HTTP 200 indicates NO technical errors, but makes no guarantee about business logic errors. Or HTTP 4xx if the incoming request had issues (e.g. In your example the HTTP 200 is an acceptable status to indicate that your "business code error message" was successfully transferred, provided that no technical issues prevented the business logic to run properly.Īlternatively you could let your server respond with HTTP 5xx if technical or unrecoverable problems happened on the server. HTTP 200 has nothing to do with success or failure of your "business code". See this wiki page for a list of all codes and their meaning.
HTTP 200 means transmission is OK on the HTTP level (i.e request was technically OK and server was able to respond properly). HTTP status codes say something about the HTTP protocol.