Note that there are some explanatory texts on larger screens.

plurals
  1. POarchitectural design for REST API with views across resources
    text
    copied!<p>Looking for some input on a REST API architectural design. I often find that the desired data is the combination of a view across multiple resources. Would you expect the client to combine them, or provide an API that does the combination for the client?</p> <p>For example, let's say we are writing a REST API for people to become notified about events. Someone will indicate interest in an event in one of 2 ways:</p> <ul> <li>Join an organization that regularly puts on events that the person has interest in</li> <li>Search for and then mark a particular event run by an organization I wouldn't normally subscribe to</li> </ul> <p>I can retrieve all of the events for user <code>100</code> by doing the following long steps:</p> <ol> <li><code>GET /user/100/organizations</code> returns <code>123</code></li> <li><code>GET /organizations/123/events</code> returns <code>[15,16,20]</code></li> <li><code>GET /user/100/savedevents</code> returns <code>[35,36]</code></li> <li><code>GET /events/15,16,20,35,36</code> returns all of the events</li> </ol> <p>But that seems rather heavy for a client. I almost want a client to be able to say, "give me all of the interesting events for this user":</p> <pre><code>GET /user/100/events </code></pre> <p>...and then require the server to understand that it has to go through all of steps 1-4 and return them, or, at the very least, return <code>[15,16,20,35,36]</code> so it becomes 2 steps: get event IDs; get event details.</p> <p>Does this even make sense, to make a view that cuts across multiple resources that way?</p> <p>EDIT: To explain further. My hesitation is because I can see how <code>/organizations/123/events</code> is a clean resource; if is identical to saying <code>/events?organizations=123</code>, i.e. "give me resource events where organizations=123". Same for <code>/user/100/organizations</code>. </p> <p>But <code>/user/100/events</code> is <strong>not</strong> "give me resource events where organizations=123". It is "give me organizations registrations where user=100, retrieve those organization ids, then give me the events where the organization=123, then give me savedevents where user=100."</p> <p>Each of the three steps itself is a clean resource mapping. Putting them together seems messy. But so does asking a client (especially a Web client), to figure out all that logic!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload