|
|
|
|
|
by neRok
378 days ago
|
|
Multiple calls?! That sounds like n*n+1. Gross :P I think the issue with the example json is that it's sent in OOP+ORM style (ie nested objects), whereas you could just send it as rows of objects, something like this; {
header: "Welcome to my blog",
post_content: "This is my article",
post_comments: [21,29,88], # the numbers are the comment ID's
footer: "Hope you like it",
comments: {21: "first", 29: "second", 88: "third" }
}
But then you may as well just go with protobufs or something, so your endpoints and stuff are all typed and defined, something like this; syntax = "proto3";
service DirectiveAffectsService {
rpc Get(GetPageWithPostParams) returns (PageWithPost);
}
message GetPageWithPostParams {
string post_id = 1;
}
message PageWithPost {
string page_header = 1;
string page_footer = 2;
string post_content = 3;
repeated string post_comments = 4;
repeated CommentInPost comments_for_post = 5;
}
message CommentInPost {
string comment_id = 1;
string comment_text = 2;
}
And with this style, you don't necessarily need to embed the comments in 1 call like this, and you could cleanly do it in 2 like parent-comment suggests (1 to get page+post, second to get comments), which might be aided with `int32 post_comment_count = 4;` instead (so you can pre-render n blocks). |
|