Should a RESTful API return 404 for arrays of objects?

dB. picture dB. · May 18, 2011 · Viewed 11.2k times · Source

Lets say there's a Product with Orders. If you ask for /products/product_id, it will return a 404 if product_id doesn't exist. But should /products/product_id/orders return a 404 if no orders exist for this product or should it return an empty array?

Answer

Darrel Miller picture Darrel Miller · May 18, 2011

I would return an empty collection. A product with zero orders is a completely valid concept, so the existence of an empty orders collection makes more sense than a 404 which would infer that this product does not have a orders collection.