title: Design of RESTful endpoint for querying based on aggregate data
body: <p>Let's say we have two resources: Person, Movie.</p>
  
  <pre><code>persons/123
  {id: 123, firstName: "John", lastName:"Travolta"}
  
  persons/124
  {id: 124, firstName: "Uma", lastName: "Thurman"}
  
  persons/125
  {id: 125, firstName: "Bob", lastName: "Saget"}
  
  persons/126
  {id: 126, firstName: "Christopher", lastName: "Walken"}
  
  persons/127
  {id: 127, firstName: "Steve", lastName: "Buscemi"}
  
  
  movies/1
  {id: 1, name: "Pulp Fiction"}
  
  movies/2
  {id:2, name: "Reservoir Dogs"}
  </code></pre>
  
  <p>Then, to relate the two, we have another resource: Cast Member</p>
  
  <pre><code>GET cast-members?movie.name=Pulp%20Fiction
  [
      {
          id: 502,
          movie: {id: 1, name: "Pulp Fiction"}
          actor: {id: 123, firstName: "John", lastName:"Travolta"},
          character: "Vincent Vega"
      },
      {
          id: 503,
          movie: {id: 1, name: "Pulp Fiction"}
          actor: {id: 124, firstName: "Uma", lastName: "Thurman"},
          character: "Mia Wallace"
      },
      {
          id: 504,
          movie: {id: 1, name: "Pulp Fiction"}
          actor: {id: 126, firstName: "Christopher", lastName: "Walken"},
          character: "Buddy Holly"
      },
      ...
  ]
  </code></pre>
  
  <p>If I want to see all of the movies Christopher Walken has been in, I know I can do this:</p>
  
  <pre><code>GET cast-members?actor.id=125
  </code></pre>
  
  <p>What if I want to see all movies where <em>both</em> Uma Thurman and John Travolta are in the Cast? What does this endpoint look like?</p>
  
  <pre><code>GET cast-members?actor.id=124&amp;actor.id=125
  </code></pre>
  
  <p>doesn't work. </p>
  
  <p>We return Cast Members where actor.id was either 124 or 125? </p>
  
  <pre><code>[
      {
          id: 587,
          movie: {id: 10, name: "Kill Bill"}, 
          // John's not in this movie
          actor: {id: 124, firstName: "Uma", lastName: "Thurman"},        
          character: "The Bride"
      },
      {
          id: 597,
          movie: {id: 11, name: "Saturday Night Fever"}, 
          // Uma's not in this movie
          actor: {id: 123, firstName: "John", lastName:"Travolta"},
          character: "Tony Manero"
      },
      ...
  ]
  </code></pre>
  
  <p>This wouldn't be what we want, because we would have to join the movies on the client side (which isn't desirable since it means we have to page through a lot of data before being able to return a result).</p>
  
  <p>the SQL query would be this:</p>
  
  <pre><code>SELECT Movie
  FROM CastMember
  WHERE Actor in (124, 125)
  GROUP BY Movie
  HAVING COUNT(DISTINCT Actor) = 2
  </code></pre>
  
  <p>Is there a way to translate this query to something that makes RESTful sense?</p>