如果一个RESTful API为对象的数组返回404? [英] Should a RESTful API return 404 for arrays of objects?

查看:334
本文介绍了如果一个RESTful API为对象的数组返回404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说有一个与订单中的产品。如果你问/产品/ PRODUCT_ID,它会返回一个404,如果PRODUCT_ID不存在。但是,应该/产品/ PRODUCT_ID /命令返回404,如果存在此产品没有订单,还是应该返回一个空数组?

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?

推荐答案

我将返回一个空的集合。零订单的产品是一个完全有效的概念,所以空单集的存在使得超过404会推断,这款产品没有一个订单收集更有意义。

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.

这篇关于如果一个RESTful API为对象的数组返回404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆