-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple sub-route controller delegation #1289
Comments
Mby django approach too will inspire someone https://www.django-rest-framework.org/api-guide/viewsets/#viewset-actions |
Have you tried using https://github.com/shekohex/nest-router ? |
@marcus-sa As mentioned above, I am aware of shekohex/nest-route. I'd prefer to deal with sub-routes at the controller level than having to define my routes at the module level. I opened this issue to see if others felt this way and if the maintainers would be willing to explore the possibility of including this functionality in NestJS. |
Hm, I fairly disagree at this point. |
I think that @marcus-sa response largely explains the reasons for closing this proposal. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Nested routes have been discussed in issues #255 and #389 which have led to the creation of the shekohex/nest-router package but I'm wondering if we couldn't implement something simpler, at the controller level. I really like how it is handled in the Jersey framework based on JAX-RS. Basically, inside your controller, you define delegation to another controller for a given sub-route. This short video gives a simple example of how it works: https://youtu.be/O4dAxOCYAUg?t=126.
In short, inside your controller, you define a path where, instead of returning a string or JSON object or whatever, you return an instance of another controller. The framework sees that and uses the "sub-controller" to handle the sub-route. How this works behind the scenes at the framework level, I do not know, but I'd be willing to investigate and see how something similar could be implemented in NestJS. Here is what it could look like:
cats.controller.ts
friends.controller.ts
I'd be willing to work on a PR for this feature if there is any interest for it.
The text was updated successfully, but these errors were encountered: