用于相关对象的RESTful API
问题描述:
我对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/
我的表示是否准确?
答
我不知道块或元块是在一个课程的上下文中,但我会像下面的东西一样。无需与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