How to Create a basic API using Django Rest Framework ?
Django REST Framework is a wrapper over default Django Framework, basically used to create APIs of various kinds. There are three stages before creating a API through REST framework, Converting a Model’s data to JSON/XML format (Serialization), Rendering this data to the view, Creating a URL for mapping to the viewset.
This article revolves around how to create a basic API using Django REST Framework. It assumes you are familiar with Django basics – Django tutorial. Also, installation of Django REST Framework. Assuming you have created a project named geeksforgeeks with Django, let’s initiate Django REST Framework.
Joining a project that uses Django REST Framework (DRF) is often stressful because of things like spaghetti code or antipatterns. I encounter the problem so often that at some point I began to wonder where that issue actually comes from. The DRF documentation is comprehensive and generally well-organized, so it should help in eliminating this issue.
That’s when I decided to analyze the thought process of a developer who has a project that is more or less ready and now wants to add a REST API to it.
Usually, he or she will have a look at this tutorial. Once the developer reads it and gets the basics, it’s time to implement its content in the application. In most cases, we want to have CRUD, and then some additional options for filtering available objects, and then some other functional endpoints like statistics or a search engine.
And suddenly, it dawned on me:
The DRF tutorial is written in reverse order, and that’s where the problem comes from. Have a look at it, and you’ll see that it attempts to show low-level versatility instead of meeting the expectations of developers and showing high-level acronyms instead.
When we read the tutorial, we first learn about the details of views, serializers, and, only at the very end, about ViewSets - a wonderfully compact way for binding everything into a neat, clear and manageable whole. But most developers never get to this place because they have already built a relatively functional API and decided to abandon the tutorial in favor of the API Guide, searching for ways of implementing their project requirements.
This article is the first one in a series where I plan to show you Django REST Framework from the general to detailed overview and help you avoid reinventing the wheel.
Follow this series, and you’ll get clear and highly manageable code that won’t bring you shame when you show or transfer it to others.
BTW. You can get the entire content of this series in a free PDF. Sounds great? Follow this link to download your copy!
Keywords:
Hyperlinked Model Serialization Django Rest API in Telugu
13 HyperLinked Model Serializer | Django Rest Framework
Model Serializer in Django REST Framework (Hindi)
Today I Coded | How to use namespaces with Hyperlinked Model Serializers in Django REST Framework
Django REST Framework Tutorial | Hyperlinks And Pagination
Django Rest Framework Tutorial.| Viewsets, Routers, Serializers, and CRUD
Hashtags:
#django #python #djangounchained #programming #quentintarantino #coding #javascript
On this page of the site you can watch the video online Hyperlinked Model Serializer in Django REST Framework - Serializers Hyperlinked model with a duration of hours minute second in good quality, which was uploaded by the user Coding Is Thinking 24 November 2023, share the link with friends and acquaintances, this video has already been watched 560 times on youtube and it was liked by 8 viewers. Enjoy your viewing!