[FEEDBACK] Clarify with DRF
See original GitHub issueI am curious to know so wants to clarify
in https://phalt.github.io/django-api-domains/plugins/#django-rest-framework
you wrote
When using DRF, we can organise the logic in a domain this way:
urls.py - Router and URL configuration. apis.py - DRF view functions or view classes. serializers.py - Serialization for models.
and
https://phalt.github.io/django-api-domains/files (let’s call this Files
section)
you have a
- models.py
- apis.py
- interfaces.py
- services.py
Plus you have this helpful diagram https://phalt.github.io/django-api-domains/styleguide/#visualisation
Can you help me to understand how the files work with DRF situation? Perhaps another diagram?
Because I cannot visualize how to use DRF on top of what you recommend under Files
Another related question is
DO you recommend the use of GenericAPIView or APIView classes in DRF for the apis.py
?
Do you mind giving a visual idea of how two different domains both using DRF would interact with one another similar to https://phalt.github.io/django-api-domains/examples/ ?
What if they are different apps of the same Django project?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
In my experience with experimenting with this styleguide, how you structure your views in
apis.py
doesn’t matter all that much, as long as it includes presentation logic. Personally, I make use of APIView and only use the put/patch/get/update/delete methods. You could simply have something like this:I also make use of serializers in
apis.py
to validate inbound data and to return serializable data.So many questions!
Let me tick off a few of the easy ones:
I almost always use
APIView
. This is a personal preference, because I like theget/post/put/delete
methods on the class, I find theretrieve/update/??/??
paradigm on viewsets hard to remember (I don’t actually remember them) and it is jarring for new users. APIView is really simple and works.If your django app is providing an API with DRF, then you just use the existing file format as I recommended, but place particular DRF logic in the files I recommened above (so add a urls.py to your domain to handle URLs, for example).
If you have two Domains in a single Django project, then why are you using DRF to talk between the two? Just use internal software APIs.