Reputation:
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.
Upvotes: 2
Views: 1674
Reputation: 54656
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.
Upvotes: 1
Reputation: 3317
I would think that you'd want to go with option 1 because your request could be successful but something fails on the backend in your api. I wouldn't return a response code of 200 all the time though, you could run into a case where say the url for the web service doesn't exist, in that case you'd want to return the appropriate response code.
Upvotes: 0