Introduction to REST & DRF Setup
REST (Representational State Transfer) is an architectural style for building web APIs. Django REST Framework (DRF) is a powerful toolkit for building REST APIs in Django. It provides serialization, authentication, viewsets, and a browsable API out of the box.
15 min•By Priygop Team•Updated 2026
REST & DRF Basics
- REST uses HTTP methods: GET, POST, PUT, PATCH, DELETE
- Resources are identified by URLs: /api/posts/, /api/posts/1/
- JSON is the standard data format for APIs
- DRF extends Django with API-specific tools
- pip install djangorestframework
- Add 'rest_framework' to INSTALLED_APPS
- DRF provides a browsable API for development/testing
- DRF handles serialization, auth, permissions, throttling
DRF Setup
DRF Setup
# Installation
# pip install djangorestframework
# settings.py
# INSTALLED_APPS = [
# ...
# 'rest_framework',
# ]
#
# REST_FRAMEWORK = {
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated',
# ],
# 'DEFAULT_AUTHENTICATION_CLASSES': [
# 'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.TokenAuthentication',
# ],
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
# 'PAGE_SIZE': 10,
# }
# REST API conventions:
# GET /api/posts/ -> List all posts
# POST /api/posts/ -> Create a new post
# GET /api/posts/1/ -> Get post with id=1
# PUT /api/posts/1/ -> Update entire post
# PATCH /api/posts/1/ -> Partially update post
# DELETE /api/posts/1/ -> Delete postTip
Tip
REST means stateless requests using HTTP methods: GET=read, POST=create, PUT=update, DELETE=remove. Each URL represents a resource.
Diagram
Loading diagram…
QuerySets are LAZY — no DB hit until evaluated.
Common Mistake
Warning
Not using proper HTTP methods. Don't use POST for everything — use GET for reading, PUT for updating, DELETE for removing.
Practice Task
Note
(1) Design a REST API for a blog. (2) Map CRUD operations to HTTP methods. (3) Define URL patterns.
Quick Quiz
Key Takeaways
- REST (Representational State Transfer) is an architectural style for building web APIs.
- REST uses HTTP methods: GET, POST, PUT, PATCH, DELETE
- Resources are identified by URLs: /api/posts/, /api/posts/1/
- JSON is the standard data format for APIs