title: What is the restful approach to compose a group by query
body: <p>consider the following http request:</p>
  
  <pre><code>GET /defects?group-by=priority
  </code></pre>
  
  <p>I would like the returned collection(feed) of defects to be grouped by their priority. i.e. the returned feed consists of defects(resources) and group infromation.</p>
  
  <p>I thought about something that will return the groups' titles and count before returning the collection, for example:</p>
  
  <pre><code>&lt;content&gt;
  &lt;Group val="High" count="567"/&gt;
  &lt;Group val="Medium" count="437"/&gt; 
  &lt;Group val="Low" count="19"/&gt; 
  &lt;Defect ,,,,&gt;
  &lt;Defect ,,,,&gt;
  &lt;Defect ,,,,&gt;
  &lt;/content&gt;
  </code></pre>
  
  <p>The problem with such representation is that the queried resource (URL) is defect so the client expects collection of Defects and not the Group element.</p>
  
  <p>I guess one option for solving this problem would be to define a separate groups resource for defects i.e.:</p>
  
  <pre><code> defects/groups?group1=priority
  </code></pre>
  
  <p>that will return collection of groups and their count, and then the client can query the defects resource for the data itself. But this design is cumbersome and requires extra round trips, not to mention possible consistency problems when defects was added\removed between the call to the group resource and the defects resource. </p>
  
  <p>Bottom line, what is the restful way to return a collection of elements grouped by an attribute?</p>
  
  <p><strong>EDIT</strong> I first thought of that this problem should be addressed by the ATOM publishing standard. But even if ATOM had addressed it, I still need to support other representations (XML, JSON) so I am looking for a pattern more inherent in the RESTful approach.</p>