I have a list of courses
with a list of students
. The idea is that a student can attend multiple courses.
The requirement is to return a unified list of courses-students where the "key" is like courseId + studentId
. The GET result will be like:
My question is, which is the best approach to define this REST GET method. I have two solutions and any idea is welcome.
GET:api-name/v1/courses/students?version=5
- mening return from all courses the all studentsGET:api-name/v1/courses-students?version=5
- in this case, is a dedicated method as courses-studentsAny idea is welcome. Many thanks!
Update: I was going to use solution 2. Also, the remark that this relation could be considered a new resource is a strong argument.
I would bet on the second option, since you are exposing a new resource, which is the relationship between courses and students - even identifiable with that "key" relating the two IDs.
Going with this option may then allow you, for example, to find the new resource with the key, or filter this new resource with query string parameters (e.g. api-name/v1/courses-students?courseId=12,45&studentId=32,67
), or request for students of an individual course (api-name/v1/courses/{courseId}/students
), or for courses of an individual student (api-name/v1/students/{studentId}/courses
).
There is a question with good answers on this topic here.