-
Notifications
You must be signed in to change notification settings - Fork 526
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
API views & urls #36
Comments
@Atorich That's a smart proposal! Thanks for taking the time 🙇♂️ One of the things we try to avoid in our projects is using the router to automatically generate URLs. We have our reasons & one of the main is "greppability" (or ease of searching for something) That said, for the folks that like to keep their URLs more RESTful, that's a good approach. I'll give it a go & extend the styleguide with your proposal 👌 |
Please, don't hurry with it. There are still some not solved issues. One of them: this approach breaks DRF api-docs because it is expected that every viewset has The quick solution is to pass something to the factory,
but it's rather ugly |
https://gist.github.com/Atorich/8e3ca27808c9f64615663ff2d1ee0bba |
👋 I'll close this for now, since some time has passed. At least for us, we are still sticking with the approach described in the styleguide. The proposed approach also looks good. Picking an approach and staying consistent is the key thing here. |
Hi 👋 I love the styleguide, but do also think that e.g. CREATE on However, using viewset factories like mentioned by @Atorich does indeed break the drf-spectacular docs. Has anyone found a better way to tackle this? |
Bumping this one ☝️ |
@stiangrim Noted. Will answer Wednesday next week (this is when I do my opensource sweep) |
@stiangrim Following-up here: What you've suggested here - tfranzel/drf-spectacular#1344 - looks like a good approach if you want to have multiple views per a single route. As an alternative, I'd also explore the routing from DRF - https://www.django-rest-framework.org/api-guide/routers/#custom-routers - and build a custom route doing pretty-much the same. Now, what I understand is that the main issue is related to If that's the case, then, perhaps, this is the same issue with the default viewsets. It looks like you need to use the Let me know if using this would get you the results you need 👍 If that's the case, then, you can build an additional layer of abstraction, to handle your general case. Cheers! |
Hi there!
First of all, I would like to say thanks for the great idea of how to organize complex things.
But I want to share some thoughts about the way to organizing views & urls.
I have found the proposed approach to register views not quite RESTful because of
/update
&/create
aren't resources.DRF's viewsets introduce a great way to do that but using them out-of-the-box contradicts to
Do 1 API per operation
rule.But we still can write separate classes for each API and use viewsets to combine them together & register via DRF router.
Here the draft of
viewset_factory
function that will help with it.And then we can just use
DefaultRouter
:and have RESTful urls with actually separated views.
The text was updated successfully, but these errors were encountered: