I have a prototype solution in AngularJS and it is working with the following data structure:
$scope.clients = [
{ client:"Client1", projects:[
{ project: "Project1", items:[
{ item: "This is the first item" },
{ item: "This is the second item" }
]},
{ project: "Project2", items:[
{ item: "This is the third item" },
{ item: "This is the fourth item" }
]}
]},
{ client:"Client2", projects:[
{ project: "Project4", items:[
{ item: "This is the fifth item" },
{ item: "This is the sixth item" }
]}
]}
];
I am looking to implement the back end and I am not sure if the API should serve the above nested data structure to the client or if it should serve a flat structure of items and then the AngularJS client app then creates the nested structure. Here is an example of the flat structure that the API would serve:
[
{ client: "Client 1", project: "Project 1", item: "This is the first item." },
{ client: "Client 1", project: "Project 1", item: "This is the second item.", },
{ client: "Client 1", project: "Project 2", item: "This is the third item.", },
{ client: "Client 2", project: "Project 4", item: "This is the fourth item.", }
];
What is the best approach for this? Additionally, is there any good references to for API design?