I have been coding using django for the past year or so and most of my work was writing API's to connect to the React-based frontend. In most of my tutorials I see people using GenericAPIViews for the basics, but I don't find anything substantial for complicated code in APIs. So to deliver my code in time, I chose the easier solution that is to use APIView where I use less abstraction, have more control over my code (by writing more code) and understand clearly the functions of my code modules.
What I'm concerned is that if I've chosen a shortcut by choosing not to learn how to use GenericAPIViews so that I can use it at its full potential. Some of the problems I faced while using GenericAPIViews or DRF in general.
- Custom permissions (e.g. I want a user who is authenticated and also have access with specific permission level (e.g can_do_xyz, or has_access_to_abc)
- Using writable serializers which might need to go through complex layers of business/app logic
- Creating entries for multiple models in the same GenericAPIView class function.
For now, the problems I have faced in my approach to use basic APIView is that the swagger documentation I've managed to write is garbage.
- I need to manually specify the query/form/path fields in the api schema docs (using AutoSchema)
- Also if an API has get/post/put/delete methods with varying fields, each of the API endpoints in swagger will show ALL the fields being used across the methods (which is understandable since I define the schema for the class and not for the separate functions). Is there any way to solve this problem?
- The delete method should only need the survey_id as parameter, while the POST/PUT method would need the body.