A
A
AlexRas2018-03-03 19:31:25
Yii
AlexRas, 2018-03-03 19:31:25

How to properly organize nested url in rest api?

Hello, there are 4 tables with such links:
5a9acc2ef0388154142366.png
How to display these links in addresses?
I tend to use nested URLs, for example:

http://site.ru/api/courses/1/categories/2/lessons/1/
http://site.ru/api/courses/1/categories/2/tasks/1/

Is it right to do so? Perhaps there are some other options?
Or is it better to use this approach:
http://site.ru/api/course-categories/1/?course_id=1
http://site.ru/api/course-lessons/1/?course_id=1&course_category_id=1

That is, enter the required get parameters to get a record in order to be 100% sure that a particular record is received or edited

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-03-03
@AlexRas

It's probably easier to post a request, and there already specify the parameters, as social networking apis often use, because you can go crazy writing rules for urlManager.
But in any case, there is no reason to use CNC for api. For the controller and action - ok, and the parameters should definitely be used like this:
?course_id=1&course_category_id=1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question