Should a RESTful API return 404 for arrays of objects?

前端 未结 4 1752
旧巷少年郎
旧巷少年郎 2021-02-03 18:58

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

4条回答
  •  鱼传尺愫
    2021-02-03 19:48

    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.

提交回复
热议问题