Let’s consider a valid and supported request to include related resources, for example, GET /posts?include=comments
. Now, if we consider the case where no post has comments, what is the best (or the recommended) approach:
- Respond with included set to an empty array:
{
"data": [ <some posts here> ],
"included": []
}
- Respond with included set to null:
{
"data": [ <some posts here> ],
"included": null
}
- Respond without a included field:
{
"data": [ <some posts here> ]
}
I did not find a clear answer by checking the specification, the forum, and the JSON Schema, so I created this post.
I believe option (1) to be the best. Also, option (3) seems to be the worst because the client may be lead into believe that the “include” query was ignored.