How to deal with a REST API returning object instead of array for collection in AngularJS?
<p>The back-end team I am working with implemented a REST API which returns collections as object (instead of array).
For example, calling <code>GET /some_resources</code> would return:
</p>

<pre><code>{
  id_1: {
          p1: "lorem",
          p2: 4 
        }, 
  id_2: {
          p1: "ipsum", 
          p2: 2
        }, 
  id_n: {
          p1: "sic", 
          p2: 7
        }
}
</code></pre>

<p>This structure is limiting to work with in Angular as you can't leverage the <strong>ng-repeat</strong> directive for instance (e.g <a href="https://docs.angularjs.org/api/ng/directive/ngRepeat#iterating-over-object-properties" rel="noreferrer">orderBy and filter do not work with object</a>).</p>

<p>For the previous example, ideally, I would rather expect an array of objects:
</p>

<pre><code>[ 
  {id: "id_1", p1: "lorem", p2: 4},
  {id: "id_2", p1: "ipsum", p2: 2},
  {id: "id_n", p1: "sic", p2: 7}
]
</code></pre>

<p>This would allow to directly work with the object returned by the <strong>ngResource</strong> service and sent it back without touching its structure. It would also allow to fully use the <strong>ng-repeat</strong> directive.</p>

<p>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.</p>

<p>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.</p>

<p>This leads to a lot of code boilerplate and I am wondering if there is an "angular way" to deal with this situation.</p>