RESTful API Url Structuring
I am stuck on how I should be structuring my URLs for a RESTful API I am developing. My problem comes from the fact that sometimes I need to get several joined tables from a single call.
In one instance, I need to get two tables. I have a table named courses, and a table named topics. I need to get the course_name row and then all the topics that belong to that course.
In another instance, I need to get three tables. I need to join the topics to the parts to the bullet_points table
How should I refer to these in the urls?
Should it be something like this? To get a single course:
courses/:course_id/
To get a course and it's topics:
courses/:course_id/topics
To get a topic and it's parts and it's bullet points:
courses/:course_id/topics/:topic_id/parts
I am new to this and so am wondering how I should really be approaching the structure of the urls.
Answers
I think your suggested URL structure is good. It also corresponds nicely to a good resource layout.
// courses $list = $model->getCourseList(); // courses/c_id $course = $model->getCourse($c_id); // courses/c_id/topics $courseTopicList = $course->getTopicList(); // courses/c_id/topics/t_id $courseTopic = $course->getTopic($t_id); // courses/c_id/topics/t_id/parts $courseTopicParts = $topic->getParts();