我需要能够根据对象的集合抢集合。 对于这一点,我考虑了几个办法,但我不知道哪一个是最有意义的,所以我会后他们俩。 如果有更好的办法,我还没有考虑,那么请随意张贴您的建议(S):)
例如,我将使用产品和评论(它们的产品评论)的资源。
目标:我们希望得到所有产品的评测
解决方法A:
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?