React Authentication: JWT, Axios, and Context API Guide

Complete guide to React Authentication. Implement login, logout, protected routes, and silent token refresh using simplified patterns.

June 20, 2025 · 5 min · 883 words · Nirajan Khatiwada

ViewSet in Django REST Framework 1. Foundation of ViewSet 1.1 What is a ViewSet A ViewSet groups related views (list, create, retrieve, update, delete) into a single class instead of separate APIView classes. Focuses on actions rather than HTTP methods. Example: Instead of UserListAPIView and UserDetailAPIView, a single UserViewSet handles all CRUD actions. 1.2 Why ViewSet Exists Reduce boilerplate code. Standardize CRUD operations. Work seamlessly with DRF routers for automatic URL generation. 1.3 Problem It Solves Compared to APIView Feature APIView ViewSet Method mapping HTTP methods (get, post) Actions (list, create) URL handling Manual URL definition Automatic via routers Boilerplate High Low Best for Highly customized endpoints CRUD-heavy resources 1.4 RESTful Action Mapping Action HTTP Method URL Pattern list GET /objects/ create POST /objects/ retrieve GET /objects/{id}/ update PUT /objects/{id}/ partial_update PATCH /objects/{id}/ destroy DELETE /objects/{id}/ Behind the scenes: DRF uses as_view() + action_map to route HTTP methods to these actions. ...

4 min · 692 words · Nirajan Khatiwada

In Python, an array is commonly implemented using a list. A list is an ordered, mutable collection that can store elements of any data type. Creating an Array with a Fixed Size Python does not have fixed-size arrays like C/C++. However, we can pre-allocate space using None. size = 10 a = [None] * size Inserting Elements into an Array We can insert values into the array using a loop. for i in range(0, len(a)): inp = input("Enter the number: ") a[i] = inp Initializing an Array at Declaration Time We can declare and insert elements at the same time. ...

1 min · 149 words · Nirajan Khatiwada

List is a linear data structure that stores elements in a sequential manner . Implementation Lists in Python We can implement a list in Python using 3 main ways: Using Array Based Implementation Using Python Inbuilt List Using Linked List Based Implementation Using Array Based Implementation class List: def __init__(self, size): self.array = [None] * size self.length = 0 self.size = size # Insert at end def insert_at_end(self, x): if self.length == self.size: return "List is Full" self.array[self.length] = x self.length += 1 # Delete at end def delete_at_end(self): if self.length == 0: return "List is Empty" deleted = self.array[self.length - 1] self.array[self.length - 1] = None self.length -= 1 return deleted # Insert at beginning def insert_at_beg(self, x): if self.length == self.size: return "List is Full" for i in range(self.length, 0, -1): self.array[i] = self.array[i - 1] self.array[0] = x self.length += 1 # Delete at beginning def delete_at_beg(self): if self.length == 0: return "List is Empty" deleted = self.array[0] for i in range(0, self.length - 1): self.array[i] = self.array[i + 1] self.array[self.length - 1] = None self.length -= 1 return deleted # Insert at position k (0-based index) def insert_at_k(self, position, x): if self.length == self.size: return "List is Full" for i in range(self.length, position, -1): self.array[i] = self.array[i - 1] self.array[position] = x self.length += 1 # Delete at position k (0-based index) def delete_at_k(self, position): if self.length == 0: return "List is Empty" deleted = self.array[position] for i in range(position, self.length - 1): self.array[i] = self.array[i + 1] self.array[self.length - 1] = None self.length -= 1 return deleted # Traverse list def traverse(self): for i in range(self.length): print(self.array[i]) # Merge with another array def merge(self, other_array, other_length): new_array = [None] * (self.length + other_length) for i in range(other_length): new_array[i] = other_array[i] for i in range(self.length): new_array[other_length + i] = self.array[i] return new_array Using Python Inbuilt List class List: def __init__(self, size): self.lists= [] # Insert at end def insert_at_end(self, x): self.lists.append(x) # Delete at end def delete_at_end(self): return self.lists.pop() # Insert at beginning def insert_at_beg(self, x): self.lists.insert(0,x) # Delete at beginning def delete_at_beg(self): self.lists.pop(0) # Insert at position k (0-based index) def insert_at_k(self, position, x): self.lists.insert(position,x) # Delete at position k (0-based index) def delete_at_k(self, position): self.lists.pop(position) # Traverse list def traverse(self): print(self.lists) # Merge with another array def merge(self, other_array): new_array = other_array + self.lists return new_array Using Linked List Based Implementation There are 3 common ways to implement linked lists: ...

2 min · 424 words · Nirajan Khatiwada

Introduction to Stack and Queue Stack and Queue are fundamental linear data structures widely used in computer science for managing ordered data efficiently. A Stack follows LIFO (Last In First Out) principle — the last element inserted is the first one to be removed. A Queue follows FIFO (First In First Out) principle — the first element inserted is the first one to be removed. These structures form the basis for more complex algorithms and systems such as parsing, scheduling, and resource management. ...

5 min · 1013 words · Nirajan Khatiwada

Trees consist of vertices (nodes) and edges that connect them. Unlike the linear data structures that we have studied so far, trees are hierarchical. They are similar to Graphs, except that a cycle cannot exist in a Tree - they are acyclic. In other words, there is always exactly one path between any two nodes. Root Node: The topmost node in a tree. Child Node: A node that has a parent node. Parent Node: A node that has one or more child nodes. Sibling Nodes: Nodes that share the same parent node. Leaf Node: A node that does not have any child nodes. Ancestor Node: A node that is a predecessor of a given node. Example: ...

6 min · 1227 words · Nirajan Khatiwada

What is a Graph? This lesson is a brief introduction to the graph data structure, its types, and the standard terminologies used to describe it. Introduction When we talk about graphs, what comes to mind are the conventional graphs used to visualize data. In computer science, the term “graph” has a completely different meaning. It is a data structure used to store and manipulate data. The graph data structure plays a fundamental role in several applications such as GPS, neural networks, peer-to-peer networks, search engine crawlers, garbage collection (Python), and even social networking websites. ...

5 min · 1062 words · Nirajan Khatiwada