2017-02-21 36 views
-1

我正在开发一个应用程序,它具有课程,章节和课程的层次结构。 一个课程不包含章节&一章包含多个课程。所以我已经定义了下面提到的URL,所以我只是想要你们的建议,如果它需要一些改变。如何在web开发中定义URL路径

/课程

/场/ <:COURSE_ID>

/章节/ <:COURSE_ID>

/章节/ <:COURSE_ID>/<:chapter_id>

/课/ <:course_id>/<:chapter_id>

/教训/ <:COURSE_ID>/<:chapter_id>/<:lesson_id>

回答

1

如果你想分层的网址,我会用这样的:

/courses/ 
/courses/<:course_id> 
/courses/<:course_id>/chapters/ 
/courses/<:course_id>/chapters/<:chapter_id> 
/courses/<:course_id>/chapters/<:chapter_id>/lessons/ 
/courses/<:course_id>/chapters/<:chapter_id>/lessons/<:lesson_id> 

或者,你可以像这样的东西去:

/courses 
/courses/<:course_id> 
/courses/<:course_id>/chapters/ 
/chapters/<:chapter_id> 
/chapters/<:chapter_id>/lessons/ 
/lessons/<:lesson_id> 

根据您的要求,您可以返回关于嵌套资源的基本信息并引用完整资源,例如像这样:

GET /courses/123 

{ 
    'title': 'My course', 
    ... 
    'chapters': [{ 
     'url': '/chapters/456' 
     'title': 'Chapter 1' 
    }] 
} 
+0

感谢建议。 – Mafia