guioconnor
guioconnor

Reputation: 414

HTTP response retrieving a resource when only partial data is available

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

  1. return 200, consider it a partial resource, handle the error data fields in the application as you would with any other data
  2. return 207 to emphasise it's not fully successfully, but 207 is not strictly HTTP.
  3. 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?

Upvotes: 4

Views: 1645

Answers (1)

Richard Green
Richard Green

Reputation: 46

You are missing the point here because a 500 is indicative of a failure of the system or the chain of communication, and since data is returned then it must be assumed that the resource exists and is found. What the OP has indicated is a partial result, implying composite data pertaining to the resource. This is necessarilly outside of the scope of http, which has done its job via a successful 200, unless you have elected a contract under which partial data is erroneous and thus a 40x.

Upvotes: 3

Related Questions