假设我们有这样的资源,
book:
type: object
properties:
author: {type: string}
isbn: {type: string}
title: {type: string}
books:
type: array
items: book
因此,当某人GET
在books资源上做出“ a” 时,我们将返回以下内容
[{"author": "Dan Brown", "isbn": "123456", "title": "Digital Fortress"},
{"author": "JK Rowling", "isbn": "234567", "title": "Harry Potter and the Chamber of Secrets"}]
我从某个工作人员那里听说,建议的REST做法是始终将响应作为JSON对象返回,这意味着我们的架构应books
如下所示,
books:
type: object
properties:
list:
type: array
items: book
所以,现在,响应看起来像这样,
{
"list": [{"author": "Dan Brown", "isbn": "123456", "title": "Digital Fortress"},
{"author": "JK Rowling", "isbn": "234567", "title": "Harry Potter and the Chamber of Secrets"}]
}
以下哪项是最佳的REST实践?