Back to Blog
Django · Python

Django REST API Tutorial for Beginners — Build Your First API in 30 Minutes

Pavan Kiran Nagapuri February 1, 2026 8 min read

Django REST Framework (DRF) is the standard tool for building APIs in Python. Whether you're building a startup MVP or a full-stack app with a React frontend, DRF makes it fast, clean, and production-ready. This tutorial walks you through building your first REST API from scratch — no prior DRF experience needed.

What is Django REST Framework?

Django REST Framework is a powerful toolkit built on top of Django that makes it easy to build Web APIs. It handles serialization (converting Python objects to JSON), authentication, permissions, and routing — all with minimal boilerplate.

Why DRF over plain Django views?

It's used by companies like Mozilla, Red Hat, and Heroku. For Indian startups and freelance projects, it's the fastest way to ship a backend.

Setting Up Your Django Project

Start with a clean virtual environment:

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install Django and DRF
pip install django djangorestframework

# Create project and app
django-admin startproject myapi .
python manage.py startapp products

Add to INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    ...
    'rest_framework',
    'products',
]

Create your model in products/models.py:

from django.db import models

class Product(models.Model):
    name = models.CharField(max_length=200)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    description = models.TextField(blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name
python manage.py makemigrations
python manage.py migrate

Creating Your First API Endpoint

Create products/serializers.py:

from rest_framework import serializers
from .models import Product

class ProductSerializer(serializers.ModelSerializer):
    class Meta:
        model = Product
        fields = '__all__'

In products/views.py, use a ModelViewSet for instant CRUD:

from rest_framework import viewsets
from .models import Product
from .serializers import ProductSerializer

class ProductViewSet(viewsets.ModelViewSet):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer

Wire up URLs in myapi/urls.py:

from django.contrib import admin
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from products.views import ProductViewSet

router = DefaultRouter()
router.register(r'products', ProductViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include(router.urls)),
]

Run the server: python manage.py runserver

Visit http://127.0.0.1:8000/api/products/ — you'll see DRF's browsable API. Your endpoints:

Testing with Thunder Client

Thunder Client is a VS Code extension — a lightweight Postman alternative. Install it from the VS Code marketplace, then:

  1. Open Thunder Client → New Request
  2. Set method to POST, URL to http://127.0.0.1:8000/api/products/
  3. Go to Body → JSON, paste: {"name": "Test Product", "price": "499.00"}
  4. Hit Send — you should get a 201 Created response
  5. Switch to GET and hit Send again — your product appears in the list

Thunder Client saves your requests as a collection, so you can re-run them anytime. Much faster than writing curl commands.

Deploying to Render for Free

Render gives you a free tier for Django apps. Here's the setup:

  1. Add gunicorn and whitenoise to your requirements: pip install gunicorn whitenoise
  2. Create requirements.txt: pip freeze > requirements.txt
  3. Add to settings.py: ALLOWED_HOSTS = ['*'] and configure WhiteNoise for static files
  4. Push to GitHub
  5. Go to render.com → New Web Service → connect your repo
  6. Build command: pip install -r requirements.txt
  7. Start command: gunicorn myapi.wsgi:application
  8. Deploy — your API is live at a .onrender.com URL

Free tier spins down after 15 minutes of inactivity, but it's perfect for portfolio projects and demos.

Next Steps — Connect to React Frontend

Now that your API is live, connecting it to React takes about 10 minutes:

# Install axios in your React project
npm install axios
// Fetch products in a React component
import { useEffect, useState } from 'react';
import axios from 'axios';

function Products() {
  const [products, setProducts] = useState([]);

  useEffect(() => {
    axios.get('https://your-api.onrender.com/api/products/')
      .then(res => setProducts(res.data));
  }, []);

  return (
    <ul>
      {products.map(p => <li key={p.id}>{p.name} — ₹{p.price}</li>)}
    </ul>
  );
}

One thing to add: CORS headers. Install django-cors-headers and add your React app's URL to CORS_ALLOWED_ORIGINS in settings. Without this, your browser will block the API calls.

From here, you can add JWT authentication, filtering, pagination, and more. This is the foundation of every React + Django full-stack project — including my GoRide app.


Need a Django Backend Built for Your Project?

I build REST APIs and full-stack Django + React applications for startups and businesses across India.

Let's Talk