title: REST: How best to handle large lists
body: <p>It seems to me that REST has clean and clear semantics for basic CRUD and for listing resources, but I've seen no discussion of how to handle large lists of resources.  It doesn't scale to dump an entire database table over the network in a resource-oriented architecture (imagine a customer table with a million customers!), especially if you only need a few items.  So it seems that some semantics should exist to filter, map and reduce a list of resources on the server-side.</p>
  
  <p>So, do you know any tried and true ways to do the following kinds of requests in REST: </p>
  
  <p><strong>1)</strong> Retrieve just the count of the resources?
  I could imagine doing something like <code>GET /api/customer?result=count</code></p>
  
  <p>Is that how it's usually done?  </p>
  
  <p>I could also imagine modifying the URL (<code>/api/count/customer</code> or <code>/api/customer/count</code>, for example), but that seems to either break the continuity of the resource paths or inflict an ugly hack on the expected ID field.</p>
  
  <p><strong>2)</strong> Filter the results on the server-side?
  I could imagine using query parameters for this, in a context-specific way (such as <code>GET /api/customer?country=US&amp;state=TX</code>).
  It seems tricky to do it in a flexible way, especially if you need to join other tables (for example, get customers who purchased in the last 6 months).
  I could imagine using the HTTP <em>OPTIONS</em> method to return a JSON string specifying possible filters and their possible values.</p>
  
  <p>Has anyone tried this sort of thing?</p>
  
  <p>If so, how complex did you get (for example, retrieving the items purchased year-to-date by female customers between 18 and 45 years old in Massachussetts, etc.)?</p>
  
  <p><strong>3)</strong> Mapping to just get a limited set of fields or to add fields from joined tables?</p>
  
  <p><strong>4)</strong> More complicated reductions than count (such as average, sum, etc.)?</p>
  
  <p>EDIT: To clarify, I'm interested in how the request is formulated rather than how to implement it on the server-side.  </p>