I’m writing a Plain Old XML HTTP request/response service and am looking for advice as to how to respond to the caller.
Given that the response is XML, would you advise:
-
Return HTTP Status 200 all the time, and embed the response success/failure inside the XML, using a kind of “return code” approach? e.g.
<myResponse><returnCode></returnCode><myPayload/></myResponse> -
Use the HTTP Status Codes to indicate success or failure.
This may be similar to this question.
Google and Amazon services use returning 200 only if your request was valid AND the response is valid.
For example using Google Contact API
I would highly recommend you do NOT always return a 200. The HTTP Status codes are designed around a response code result that represents the request. As shown above, if you request is not correct, then using HTTP Status codes is a valid solution.
I would recommend using a 5XX if there is a problem on your end. I really wish Google would do this. (At one point their Experimental OAuth 2.0 endpoint was not working, and instead of throwing a 503 – Service Unavailable, I was getting a 400 – Bad Request, which made me thing I was doing something wrong….)
For descriptions of the HTTP Status Codes check out RFC2616.