Python

What is Django Rest Framework?

Django Rest Framework lets you create RESTful APIs: A way to transfer information between an interface and a database in a simple way.

  1. Django REST framework (DRF) is an open-source, mature, and well-supported Python/Django library.
  1. It aims at building web Rest APIs.
  1. The Django REST framework contains a wide set of out-of-the-box features, but the core view class is very simple and the framework in general is easy to use.

Steps to start with Django rest framework

Setting Up environment:

python3 -m venv env

source env/bin/activate

(On Windows, run source env\Scripts\activate instead.)

Install Django and Django Rest Framework:

django-admin start project blog

cd blog

django-admin startapp api

Run Migrations:

python manage.py makemigrations

python manage.py migrate

Create SuperUser(Admin):

A. python manage.py createsuperuser –email admin@example.com –username admin

Set up your Django REST Framework API

INSTALLED_APPS[

#code omitted for brevity

‘rest_framework’,

‘api.apps.ApiConfig’,

]

Start the local development server:

python manage.py run server

These are the basic things we can do to start a Django rest framework project.

Why choose Django Rest Framework for Development?

One of the main reasons for using the Django rest framework is that it makes serialization so easy and fast.

  1. Here APIs play a major role, if you create APIs of the common business logic, then you just need to access those APIs using URLs in your different applications.
  1. The Django REST Framework, then, plays nicely with the Django ORM that makes handling database queries easy. With a few lines of code you can serialize your database models to REST-ful formats.
  1. The main idea behind the DRF is to clearly divide a model, the generalized wire representation (e.g. JSON, XML, etc.), and set of generic Class-Based-Views that can be customized to satisfy the specific API endpoint using Serializer that describes the mapping between them.

Django Rest Framework Authentication

Authentication is the mechanism of associating an incoming request with a set of identifying credentials, such as the utilizer the request emanated from, or the token that it was signed with.

The sanction and throttling policies can then utilize those credentials to determine if the request should be sanctioned

Types of Authentication: 

  1. Basic Authentication
  2. Token-Based Authentication
  3. 3rd Party Packages

Django Rest Framework APIView

Django’s views are a welcome departure from the old-style views. we’re migrating an existing RESTful API based on function-based views to class-based views.

There are mainly 2 types of Views:

  1. Function-based Views
  2. Class Based Views

We will explore different ways to engender a Django Rest Framework(DRF) API in a 3 part series:

  1. Plain APIView
  2. Generic APIView
  3. ViewSets

Congratulations! Now you are ready to start with the Django rest framework. After reading this you are able to set up and run a Django rest framework project. After reading this you are ready to learn the following things:

  1. Create Serializer
  2. Create Models
  3. Create Views
  4. Register Url Patterns
  5. Attach Different Rest APIs with URLs
  6. You can create API for login authentication.
Aniruddh Agarwal

Founder and CEO of Extern Labs Inc. and A Proven Multi-Skill Developer. I help Startups and Businesses in building their dream projects with advanced tech. tools.

Published by
Aniruddh Agarwal

Recent Posts

WordPress vs Strapi: Choosing the Right CMS for Your Next Project

In the ever-evolving landscape of website development, selecting the right Content Management System (CMS) is… Read More

February 27, 2024

Exploring the Pros and Cons of AR & VR in EduTech

Education is a realm constantly evolving with technological advancements. Augmented Reality (AR) and Virtual Reality… Read More

December 12, 2023

How Digital Menu can Add Good Value to Your Restaurant Business

In today's dynamic culinary landscape, restaurants are not just about serving delectable dishes; they're about… Read More

December 6, 2023

Top 5 Innovations Revolutionizing in Real Estate Industry

The real estate industry has a rich history deeply embedded in the fabric of human… Read More

December 4, 2023

The Changing Face of eCommerce: Evolution, Trends, and the Role of AR/VR Technology

The landscape of eCommerce has experienced a remarkable evolution over the past few decades, transforming… Read More

December 1, 2023

Top 5 Programming Languages & Frameworks for Mobile App Development

Mobile app development has become an integral part of our lives, with nearly every aspect… Read More

September 27, 2023