Answer the question
In order to leave comments, you need to log in
Relationships in RESTful API?
Hello. I'm making (trying) a SPA running on a REST API.
I have a Post entity that is related to a Comment entity (one-to-many), and a Comment entity is related to a Comment_Likes entity (one-to-many):
Post
id
title
content
Comment
id
content
post_id
Comment_Likes
id
user_id
comment_id
-request at the url site.com/posts, can I return such a response, which will contain all the relationships 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
}]
}]
}]
Answer the question
In order to leave comments, you need to log in
Well, a huge bunch of articles on the Internet on this topic, for example: https://habr.com/ru/company/hexlet/blog/274675/
And the question that you ask refers to API design, and here you already have to break a huge one about this stone bunch of copies. Do what makes it easier to use. On the other hand, OData, Protobuf\GData, RAML, GraphQL and other add-ons over REST solve one of these problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question