2013-07-05 50 views
1

我對REST相當陌生,並且一直在努力繪製出與mySQL數據庫中的外鍵相關的對象的RESTful請求。用於相關對象的RESTful API

我有以下對象和它們的關係是線性順序:

Quiz_course [1] 
Quiz_meta_block [2] 
Quiz_block [3] 
Quiz_question [4] 

到目前爲止,我想出了以下GET請求:

// Retrieve all quiz_course(s) 
api/quiz_course/ 

// Retrieve quiz_course by id 
api/quiz_course/{id} 

// Retrieve all quiz_meta_blocks related to a quiz_course id 
api/quiz_course/{id}/quiz_meta_block 

// Retrieve a quiz_meta_block that is related to a quiz_course_id 
api/quiz_course/{id}/quiz_meta_block/{id} 

但後來我想,當撞牆得到quiz_questions:

// Retrieve all quiz_questions that is related to a quiz_course_id 
api/quiz_course/{id}/quiz_meta_block/quiz_block/quiz_question/ 

我的表示是否準確?

回答

2

我不知道塊或元塊是在一個課程的上下文中,但我會像下面的東西一樣。無需與quiz_前綴一切*

../courses 
../courses/n 
../courses/n/meta-blocks 
../courses/n/meta-blocks/n 
../courses/n/meta-blocks/n/blocks 
../courses/n/meta-blocks/n/blocks/n 
../courses/n/meta-blocks/n/blocks/n/questions 
../courses/n/meta-blocks/n/blocks/n/questions/n 

你也可以給直接訪問,比方說,在所有的過程類似這樣的問題:

../courses/n/questions