Note that there are some explanatory texts on larger screens.

plurals
  1. POREST interface usage for multiple resources
    primarykey
    data
    text
    <p>I am currently adding a REST API over http to an online service and I am confronted with a very simple problem for which I cannot find an answer that satisfies me:</p> <p>I have mainly 2 resources: 'user' and 'reports', as you would have guessed reports are associated to users (to one and only one, = foreign key in my db)</p> <p>Anyway I have this url mapping for <code>GET</code> :</p> <ul> <li><code>mywebsite/api/users/{id}</code> : returns a user and related information, or a list of users if id is not present</li> <li><code>mywebsite/api/report/{id}</code> : returns a report and related information, or a list of reports if id is not present</li> </ul> <p>Now I would like to get the reports for a specific user, my way of doing it now is to add an optional parameter to the <code>GET</code> method for reports: <code>?username={username}</code> and if it is present, I am filtering the results to return only the reports for this user.</p> <p>I can't help but think something is wrong... if I start doing things like this I will have my methods handling <code>GET</code> full of if/else looking for missing parameters...</p> <p>Other solutions I I thought of are:</p> <ul> <li>incorporate the reports in the resulting <code>GET</code> on <code>mywebsite/api/users/{id}</code> but I have many many reports so in the end it will become really bad...</li> <li>map another url just for this function, but it just doesn't feel right...</li> </ul> <p>I am just getting the grips of this REST thing, I like the concept but a little explanation on this matter would really help me understand it better.</p> <p>Thanks</p> <p><strong>Edit:</strong></p> <p>It seems I have hit a common problem in the REST world, I have tied my resources to a model. If you tie a resource to a model you end up having trouble with aggregate attributes. Some guy describes this error here <a href="http://jacobian.org/writing/rest-worst-practices/" rel="nofollow noreferrer">http://jacobian.org/writing/rest-worst-practices/</a> but I have yet to understand how to manage that as he said...</p> <p><em>fyi I am using django/piston but this question should be answerable regardless of any language.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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