Assume we have resources like this,
book:
type: object
properties:
author: {type: string}
isbn: {type: string}
title: {type: string}
books:
type: array
items: book
So, when someone makes a GET
on the books resource, we would be returning the following
[{"author": "Dan Brown", "isbn": "123456", "title": "Digital Fortress"},
{"author": "JK Rowling", "isbn": "234567", "title": "Harry Potter and the Chamber of Secrets"}]
I heard from someone at work that the recommended REST practice is to always return responses as JSON objects, which would mean that our schema for books
would look like this,
books:
type: object
properties:
list:
type: array
items: book
So, now, response would look like this,
{
"list": [{"author": "Dan Brown", "isbn": "123456", "title": "Digital Fortress"},
{"author": "JK Rowling", "isbn": "234567", "title": "Harry Potter and the Chamber of Secrets"}]
}
Which of these is the best REST practice?