【发布时间】:2016-03-22 20:17:33
【问题描述】:
假设我有两个表,书和作者,其中每本书都有一个作者的外键。 /books/ 端点返回存储在系统中的所有书籍的列表。现在假设客户端将使用此列表,并按作者对其进行分组。让服务器返回按作者嵌套和分组的数据以使客户端不需要返回是否是 RESTful?是否有请求响应分组方法的标准? (可能类似于/books/?groupby=author)
例如:
// flat
[
{'title': 'Harry Potter', 'author': 'JK Rowling'},
{'title': 'Harry Potter 2', 'author': 'JK Rowling'},
{'title': 'Harry Potter 3', 'author': 'JK Rowling'},
{'title': 'Lord of the Rings', 'author': 'J. R. R. Tolkien'},
]
对
// nested
[
{'author': 'JK Rowling', books:
[
{'title': 'Harry Potter'},
{'title': 'Harry Potter 2'},
{'title': 'Harry Potter 3'},
]
},
{'author': 'J. R. R. Tolkien', books:
[
{'title': 'Lord of the Rings'}
]
}
]
【问题讨论】:
-
我认为这种操作没有标准。分组可以由客户完成,也可以作为您提到的另一种方法提供。
-
看看 JSON 指针。
标签: rest restful-architecture restful-url