MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Endpoints for Models0%
Study Materials
REST API Development with DjangoProgress 0%
1.1REST Principles1.2HTTP Methods Overview1.3Status Codes
3.1Create, Retrieve, Update, Delete APIs3.2Endpoints for Models3.3URL Routing
HomeTutorialsREST API Development with DjangoEndpoints for Models
URL Routing

Endpoints for Models

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Designing Clean RESTful Model Endpoints

Designing an intuitive, predictable REST API is an art. Clean API endpoints conform to standard industry conventions, use intuitive hierarchical relationships, handle query parameters cleanly, and provide consistent metadata wrappers.


1. RESTful URL Design Standards

1Standard REST Hierarchy:
2/api/v1/{collection}/ ──► Collection Endpoint (GET list, POST create)
3/api/v1/{collection}/{id}/ ──► Detail Endpoint (GET, PUT, PATCH, DELETE)
4/api/v1/{collection}/{id}/{sub-collection}/ ──► Nested Resource Endpoint

Golden Rules:

  1. 1
    Always use lowercase plural nouns: /api/v1/customers/ (not /Customer or /getCustomer).
  2. 2
    Represent hierarchies naturally: /api/v1/projects/{id}/tasks/ indicates tasks belonging to a specific project.
  3. 3
    Limit nesting depth: Avoid nesting deeper than 2 levels (/orgs/1/projects/2/tasks/3/comments/4 is an anti-pattern!). Flatten deep children: /api/v1/tasks/{task_id}/comments/.
  4. 4
    Use query parameters for filtering and pagination: /api/v1/articles/?status=published&category=tech&page=2.

2. Implementing Nested Child Endpoints in DRF

1# tasks/views.py
2from rest_framework.viewsets import ModelViewSet
3from rest_framework.permissions import IsAuthenticated
4from .models import Task
5from .serializers import TaskSerializer
6 
7class ProjectTasksViewSet(ModelViewSet):
8 serializer_class = TaskSerializer
9 permission_classes = [IsAuthenticated]
10 
11 def get_queryset(self):
12 # Scope tasks strictly to project ID extracted from URL kwargs
13 project_id = self.kwargs["project_pk"]
14 return Task.objects.filter(project_id=project_id, project__owner=self.request.user)
15 
16 def perform_create(self, serializer):
17 project_id = self.kwargs["project_pk"]
18 serializer.save(project_id=project_id)

3. Response Structure & Metadata Envelopes

While standard DRF endpoints return bare JSON arrays or objects, enterprise platforms frequently wrap responses in standard metadata envelopes:

1{
2 "data": {
3 "id": "proj_9912",
4 "name": "Cloud Security Architecture",
5 "status": "active"
6 },
7 "meta": {
8 "timestamp": "2026-09-15T04:45:00Z",
9 "version": "v1.2"
10 }
11}

4. Sub-resource Actions via @action

When a model needs a non-CRUD business operation (e.g. archiving a project or sending an invoice):

1from rest_framework.decorators import action
2from rest_framework.response import Response
3 
4class ProjectViewSet(ModelViewSet):
5 queryset = Project.objects.all()
6 serializer_class = ProjectSerializer
7 
8 # POST /api/v1/projects/{pk}/archive/
9 @action(detail=True, methods=["post"], url_path="archive")
10 def archive_project(self, request, pk=None):
11 project = self.get_object()
12 project.status = "archived"
13 project.save()
14 return Response({"status": "Project archived successfully"})

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which of the following is considered a best-practice RESTful URI design?
Question 2
Why is deep URL nesting (e.g. /companies/1/departments/2/teams/3/members/4/tasks/5/) discouraged?
Question 3
How do you define a custom RPC-style action on a single model instance in a DRF ViewSet?
Question 4
What does the detail=False argument on an @action decorator indicate?
Question 5
Why should API versioning (e.g. /api/v1/) be included in endpoint URI designs from day one?
Next Lesson

URL Routing

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Create, Retrieve, Update, Delete APIsURL Routing

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master REST API Development with Django with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext