drf-nested-routers icon indicating copy to clipboard operation
drf-nested-routers copied to clipboard

api root

Open Jcbobo opened this issue 9 years ago • 18 comments

nested resources not showed in api root

Jcbobo avatar Jul 15 '15 15:07 Jcbobo

Hi. Can you elaborate, with a minimal example please?

alanjds avatar Aug 24 '15 03:08 alanjds

I will use the example in the docs

with from rest_framework_nested import routers from views import DomainViewSet, NameserverViewSet (...)

router = routers.DefaultRouter() router.register(r'domains', DomainViewSet)

domains_router = routers.NestedSimpleRouter(router, r'domains', lookup='domain') domains_router.register(r'nameservers', NameserverViewSet)

urlpatterns = patterns('', url(r'^', include(router.urls)), url(r'^', include(domains_router.urls)), )

the routers are working, but when you go to the api-root view the view NameserverViewSet is not showed in the browsable api

I hope now is clear (sorry for the really poor detail)

Jcbobo avatar Aug 24 '15 07:08 Jcbobo

@Jcbobo88 How should the default router display the nested URLs? They are not supposed to show up as the default router only shows the top level resources by design. Linking to those nested resources can be done by a modified HyperlinkRelatedFields and such.

jsenecal avatar Aug 27 '15 14:08 jsenecal

Seems reasonable for me to close the issue. Do you agree @Jcbobo88 ?

alanjds avatar Sep 10 '15 21:09 alanjds

I agree that the links to nested resources should be from elsewhere than the api root.

ryanhiebert avatar Nov 04 '15 19:11 ryanhiebert

I think that having the nested resource listed in the api root can help developers that need to use that resources, (all api listed and described in a single point), if you think there is a better option is the same. I did not understand how access the lists of nested resources.

Jcbobo avatar Nov 17 '15 08:11 Jcbobo

I see your perspective. The problem comes when you attempt to generate the links to those nested routes. Which context are they a part of?

I'm not sure that this is something that the auto generated too can handle automatically in a sane way. I think that you'll have to end up making that serializer and viewer manually.

Do you have a better answer as to how to make the links to the sub resources?

ryanhiebert avatar Nov 17 '15 12:11 ryanhiebert

No i don't have, I just come back from hospital some day ago and start to look the mail... ( no one of mine colleagues care about that aspect so they skip it)

Jcbobo avatar Nov 17 '15 12:11 Jcbobo

Calm down, dudes :)

I tend to prefer less info, than the whole API Tree on the 1st page. It could hurt the service if is too big, but maybe it can be a on-off switch...

alanjds avatar Nov 17 '15 14:11 alanjds

I don't have a particular problem with having an option to have all the routes on the main router. I just don't see a way to get the links for the nested routes. If that was figured out, then I'd no longer have a problem.

Off the top of my head the only way I can think to do that would be to use URI templates instead of straight hyperlinks. I don't know if it's feasible to generate URI templates from regex routes. Because of that, it makes me think that it's likely going to have to be custom rather than auto-generated.

I agree with @alanjds preference of less info on the 1st page, but I don't mind exploring the option of more if someone wants to figure out how that could be done.

ryanhiebert avatar Nov 17 '15 14:11 ryanhiebert

Hi, I'm a new user of this module. I switched from DefaultRouter to SimpleRouter and now I'm getting an 404 error in the API Root.

How I can fix this issue? thanks!

beigna avatar Sep 19 '17 14:09 beigna

@nachopro I guess your issue is another. DRF SimpleRouter does not include the API Root, so nested_routers does not. See this docs: http://www.django-rest-framework.org/api-guide/routers/#defaultrouter

alanjds avatar Sep 19 '17 14:09 alanjds

@nachopro : That's right, you need to be using this package's NestedDefaultRouter for the API root. Check out the example in the README file.

ryanhiebert avatar Sep 19 '17 15:09 ryanhiebert

@alanjds I missed this line: https://github.com/alanjds/drf-nested-routers/blob/master/rest_framework_nested/routers.py#L30

I am ashamed. Sorry for the inconvenience and thank you very much for your time.

beigna avatar Sep 19 '17 16:09 beigna

@nachopro :) No problem.

alanjds avatar Sep 26 '17 15:09 alanjds

Was this ever resolved? Seems like discussion ended at release 91, but I don't see what the resolution is.

I personally think the option of showing the nested APIs in the API root would be beneficial for developers.

keithhackbarth avatar Dec 16 '18 16:12 keithhackbarth

I agree with @alanjds preference of less info on the 1st page, but I don't mind exploring the option of more if someone wants to figure out how that could be done.

As @ryanhiebert said, nobody opposed to it, but nobody stepped in and coded it.

Anyway, I would be happy with such PR if it have an on-off switch.

alanjds avatar Dec 16 '18 20:12 alanjds

Could we maybe use "actions" for it? To show possible child relations within the actions dropdown? The actions button/functionality has since 2018 got a major update, so now might be the time for it.

gabn88 avatar Oct 10 '23 13:10 gabn88