The back-end team I am working with implemented a REST API which returns collections as object (instead of array).
For example, calling GET /some_resources
would return:
{
id_1: {
p1: "lorem",
p2: 4
},
id_2: {
p1: "ipsum",
p2: 2
},
id_n: {
p1: "sic",
p2: 7
}
}
This structure is limiting to work with in Angular as you can't leverage the ng-repeat directive for instance (e.g orderBy and filter do not work with object).
For the previous example, ideally, I would rather expect an array of objects:
[
{id: "id_1", p1: "lorem", p2: 4},
{id: "id_2", p1: "ipsum", p2: 2},
{id: "id_n", p1: "sic", p2: 7}
]
This would allow to directly work with the object returned by the ngResource service and sent it back without touching its structure. It would also allow to fully use the ng-repeat directive.
When I asked the back-end team to change the structure of their response of collections from object to array, they argued that the API consumer should not lead the design of the structure for the response.
I partially agree with their argument, so for now, the only solution I found consist in transforming the object into an array, work with this object into my scope and retransform the array back to the original object structure, before sending it back to the API.
This leads to a lot of code boilerplate and I am wondering if there is an "angular way" to deal with this situation.