I apologise if there is an answer for this already. I found related questions (e.g. HTTP status code for a partial successful request) but not exactly the same.
I'm building an API that returns data that is aggregated from multiple sources. Sometimes, some critical part of the data is unavailable and the client has to be made aware and error data is included in the response.
Other than the severity of the missing field(s), the rest of the resource is valid and useful and could be regarded as a partial update (e.g. if you only had permissions to see part of a resource).
So far, the options are
- return 200, consider it a partial resource, handle the error data fields in the application as you would with any other data
- return 207 to emphasise it's not fully successfully, but 207 is not strictly HTTP.
- return 500 and handle the successfully returned data in the application as you would on a 200
I'm partial to option 1 but I'm not fully convinced. Is there a clear way of handling this? Perhaps defining a specific content-type?
X-Response-Type: partialand instruct your clients to refer to the value before processing the response data if they receive a code 500200and indicate what data is missing in the response body (your option #1). REST, as far as I know, is very resource-centric and, since in your case the resource is valid and useful (and, in other words, "it exists"),200seems to be the best choice. It's also probably not a good idea to fool withcontent-typeas this may confuse some clients. Just go with plainapplication/json(or XML). I also notice that a lot of APIs tend to "err" towards200and return rich statuses as data. Seems more "idiomatic" this way.