Not sure where to go for an authoritive/text book answer for this question.

Suppose a service returns a list of something e.g. Customer, Employee, Fruits, etc.

What should be returned when the list is empty?

I am working with people using SOAP, and they are sure that just a "success" result is enough.

Is there a analogue of LSP in OOP for SOA world? I mean should the there be a type compatibility? For example, returning a list object with a single definition with no values for homegnousity.

SQL Database theory used relational calculus for rigour, what is the the analogue for API REST,SOAP or otherwise in terms of type compatibility etc.

PS : this is not about preference, but about the stablished patterns and practices. There must be somethig similar to OOP design patterns for APIs.

  • Consider how it is being consumed. I would lean toward returning an actual empty list. A Success code might be sufficient, but the receiver still has to check to see if a list is returned and handle numerous branches. However if you always return the list (or whatever base object) a receiver on success knows it can always deserialise to a given type successfully (otherwise it is certain that the connection was prematurely terminated and it did not receive the entire response).
    – Kain0_0
    Aug 6, 2019 at 6:27
  • @Kain0_0 not about my preference, looking for api design refrence, what are the stblished patterns?
    – jimjim
    Aug 6, 2019 at 6:36
  • 1
    ? I'm failing to see how that was a preference. I pointed out the extra design effort being enforced on each and every client to handle a discontinuous edge case - and how homogeneity avoids that. As for references google it, everyone has a different opinion. As for Rigour, REST is quite clear about that. Take a read of the literature.
    – Kain0_0
    Aug 6, 2019 at 7:12
  • @Kain0_0 : Thank you for the academic refrence, the problem with google search is that I have already tried it and all I see is ideas of some company or blogger, nothing definitive as a text book or protocol definition.
    – jimjim
    Aug 6, 2019 at 7:59

1 Answer 1


what should be retruned when the list is empty?

In an HTTP API, the message-body of the response would normally contain a representation of an empty list. For example, if you were using application/json, then the message body would look like


The response code would normally be 200 OK: there were no faults with the request, the server was able to find a current representation of the resource in question, the representation can be cached, and so on.

If you are returning a media type (text/plain, perhaps?), where the representation of a list is zero bytes long, then you might prefer to use 204 No Content as the response code.

Edit: I would no longer suggest the use of 204 simply because the content is zero bytes long. 204 No Content has semantics specific to a remote authoring edge case, and that meaning really doesn't make sense when you are returning a representation of the resource.

Instead, just do the boring thing and return 200 OK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.