I'm learning how to make a good REST API. So, suppose I have the following models:
Post
has title, body, publish_date
has_many comments, authors
Comment
has author, publish_date
So, if I call GET /post
, to get all posts, how it's comments should be returned? I'm thinking in something like:
{
'post/1': {
'title': 'My first post',
'body': 'a big body',
'publish_date': '20121120',
'comments': 'post/1/comments',
'authors': 'post/1/authors'
},
'post/2': {
'title': 'Another post',
'body': 'a REALLY BIG body',
'publish_date': '20121121',
'comments': 'post/2/comments',
'authors': 'post/2/authors'
}
}
I'm also thinking in put each comments' resources direct in /post
response, like
'comments': {
'post/1/comment/1',
'post/1/comment/2',
'post/1/comment/3'
}
So, what's the best approach?