Relationships in a RESTful API?

Hello. I do (try to) SPA REST API. I have a Post entity that is associated with the Comment entity (one to many), and the Comment entity associated with the entity Comment_Likes (one to many):



I am worried about - when I do a Get request on the url, can I return this answer, inside which will contain all relations at once? -
 "id": "1",
 "title": "First post",
 "content": "Content of first post",
 "comments": [{
 "id": "1",
 "content": "First comment",
 "likes": [{
 "user_id": 1,
 "comment_id": 1

It is REST or not REST? And if you don't REST, then how to make it more like him? I read that suezanne model should be returned in the form of links to the resources. But it turns out that instead of having to make one http request I have to make hundreds of queries to my service more like Restful?
March 19th 20 at 08:31
1 answer
March 19th 20 at 08:33
Well a huge bunch of articles online on this topic, for example:

And the question you ask applies to API design and there are not going to break the stone the great cloud of copies. Do as it will be more convenient to use. On the other hand one of these problems decide OData Protobuf\GData, RAML, GraphQL and other add-ons over the REST.
I should add that comment_likes is a relationship many to many in your concept. It turns out that one likes can be multiple users. You could, but not beautiful, not logical and resource-intensive. Best is not too late to delete the table and add likes_count field in the comments table. - sterling_Krajc commented on March 19th 20 at 08:36

Find more questions by tags RESTful API