title: RESTful search for deep nested resources
body: <p>I need to implement a search that in my head sounds more suited for SOAP than a RESTful service so I am struggling expressing it in as a REST endpoint.</p>
  
  <h2>Domain Model</h2>
  
  <p>Company(<strong>companyId</strong>)<br>
  Contract(<strong>contractId</strong>, companyId, privilegeGroupId)<br>
  PrivilegeGroup(<strong>privilegeGroupId</strong>, privilegeId)<br>
  Privilege(<strong>privilegeId</strong>)  </p>
  
  <p>Primary keys in bold.</p>
  
  <h2>Search in SOAP terms</h2>
  
  <p>findPrivilegesByCompanyId</p>
  
  <h2>RESTify SOAP requests</h2>
  
  <p>I have tried in many ways to hammer this query to some kind of REST request but nothing is really convincing me because privileges and companies do not have a direct relationship.<br>
  The actual relation is represented by this long URI: </p>
  
  <p><em>/companies/{companyId}/contracts/privileged-groups/privileges</em></p>
  
  <p>However, even though this URI speaks the truth, it doesn't seem a good idea exposing it to the API clients. So I am trying to come up with some alternatives:</p>
  
  <ul>
  <li>GET /companies/{companyId}/privileges</li>
  <li>GET /privileges/search?companyId={companyId}   </li>
  </ul>
  
  <p>Any idea on how to handle those scenarios? How to express those kinds of queries in a RESTful API? Is it even possible? I think that in theory, the result of this query is not even a resource in REST terms.  </p>
  
  <p>Note: the API already exposes CRUD operations for each object of the domain model. </p>