我需要能够获取基于对象集合的集合。为此,我正在考虑几种方法,但不确定哪一种最有意义,所以我会同时发布它们。如果有更好的方法我可能没有考虑过,请随时发表您的建议:)
例如,我将使用产品和评论(产品评论)作为资源。
目标:我们希望获得所有产品的评论
方法一:
POST api/Products { json: filters, limits, etc } // returns api/Products/<id>
GET api/Products/<id>/Reviews { json: filters, limits, etc } // returns json array
// ... of reviews present in products
// id in this case would refer to the collection, which would be cached
方法 B:
GET api/Reviews { json: filters } // returns json array of reviews, but needs to
// ... have either all of the product ids passed as an array (not practical with
// ... huge collections), or needs to have all of the api/Products filters passed,
// ... in which case making the code unDRY
方法 C:
GET api/Reviews { json: filters: { products: 'api/Products?filters' }...
// is this reasonable?
提前感谢您的帮助,如果这个问题是菜鸟,我深表歉意,我还是 REST 新手
方法 D:
access individual products
GET api/Product/<id>
access collection of products:
POST api/Products?filters=stuff..
GET api/Products/<id>
access collection of products' reviews
POST api/Products/<id>/Reviews?filters=stuff
GET api/Products/<id>/Reviews/<id>
... this would thus allow us to cache the result easily, does this seem reasonable to you?