drf-nested-routers
drf-nested-routers copied to clipboard
api root
nested resources not showed in api root
Hi. Can you elaborate, with a minimal example please?
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)
@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.
Seems reasonable for me to close the issue. Do you agree @Jcbobo88 ?
I agree that the links to nested resources should be from elsewhere than the api root.
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.
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?
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)
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...
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.
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!
@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
@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.
@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.
@nachopro :) No problem.
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.
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.
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.