yii-api icon indicating copy to clipboard operation
yii-api copied to clipboard

Nested fields and expand in REST API

Open yii-bot opened this issue 7 years ago • 3 comments

This issue has originally been reported by @ghost at https://github.com/yiisoft/yii2/issues/8061. Moved here by @samdark.


Facebook Graph API also uses fields and expand query parameters in REST APIs. Now Yii2 supports same but upto 1 level. Can we do nested fields like Facebook, for example:

GET graph.facebook.com/me?fields=albums.limit(5){name, photos.limit(2){name, picture, tags.limit(2)}},posts.limit(5)

In above example, my albums are limits to 5 only and again in each album only name and photos fields will be fetched with max 2 photos per album with again photos nested to give max 2 tags per photo. Along with albums, it will also give max 5 posts of the user.

Now limit(n) would be advance feature but I think nested expand is something easy to implement and really necessary feature to have.

PS: On separate note if you plan to support nested limit, you can also look into offset and sort on nested elements.

yii-bot avatar Apr 05 '18 23:04 yii-bot

+1

mitrm avatar Apr 16 '18 19:04 mitrm

+1 I think nested field is very useful. limit is useful, but is not so important, it can be implemented with extraFields


sorry, I find the nested field is already in master #6844 of yiisoft/yii2

lubobill1990 avatar Apr 19 '18 05:04 lubobill1990

Great to have this as a feature.

samdark avatar Sep 08 '20 15:09 samdark