Let's say that the domain structure of anapplication is as follows:
- There is domain object called Department.
- There is a domain object called Student.
- There is a domain object called Paper.
- The relationship between Student and Department is many-to-many.
- A student can publish (create) a Paper for himself or for a particular Department.
- A student can view all the papers published by him for himself and for departments to which he belongs (the latter includes papers published by other students belonging to the same department as the given student)
Here is what I think the restful uri designs should be like
- Student creates (POST) a white paper for himself :
/students/{studentid}/papers - Student creates (POST) a white paper for a particular department
/students/{studentid}/departments/{departmentid}/papers - Get all student papers published by him for himself /students/{studentid}/papers/self
- Get all student papers published by him for himself including the papers of the departments to which he belongs /students/{studentid}/papers
- Similar get requests for point number 1 and 2.
The other way to arrive at the above end points would be something like (considering only points 1 and 2) :
/students/{studentid}/papers
and then pass departmentid in the request body. The application would the check for the presence of departmentId in the request. If it's not null then it will assume that this paper is being published for the given departmentid, otherwise for the student himself.
Which one of the above would be a better approach?