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();

Need Your Help

In what situation do you use a semaphore over a mutex in C++?

c++ multithreading semaphore

Throughout the resources I've read about multithreading, mutex is more often used and discussed compared to a semaphore. My question is when do you use a semaphore over a mutex? I don't see semapho...

Template trouble with Visual Studio 2010

c++ visual-studio-2010 templates

With GCC in Linux, this following code compiles well. But with visual studio, an error C2893 occurs. Do you have any ideas ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.