This might be and obvious questions, however I'm not seeing any documentation that directly addresses the how backbone prefers JSON to be formatted from a REST API source.
Ideally I would like to reduce the number of API calls by including inside the post and a few of the most recent comments.
For instance
Say I were retrieving post number 404. Using a GET to http://api.example.com/v1/posts/404.json
using .get(404)
I would think a nested JSON would be convenient/clean:
{
"id": 404,
"title": "Hans shot first.",
"comments": [
{
"id": 4041,
"body": "But not anymore!"
},
{
"id": 4042,
"body": "Indeed he did."
}
]
}
Ember.js seems to prefer using relational ids. source Does Backbone.js prefer similar?
{
"post": {
"id": 404,
"title": "Hans shot first.",
"comment_ids": [4041, 4042]
},
"comments": [{
"id": 4041,
"body": "But not anymore!"
},
{
"id": 4042,
"body": "Indeed he did."
}]
}
I found related posts at Backbone.js restful json API design, and Backbone.js & REST API resources relationship & interraction, among others. However they lack examples of the actual internal JSON structure recommendations. Backbone Fundamentals