from rest_framework.test import APIRequestFactory factory = APIRequestFactory() request = factory.get('/users')
from rest_framework.test import APIRequestFactory from myapp.views import UserView factory = APIRequestFactory() data = {'name': 'John', 'age': 30} view = UserView.as_view() request = factory.post('/users', data=data) response = view(request)In Example 1, we create a GET request for the URL '/users' using the APIRequestFactory. In Example 2, we create a POST request to create a new user using the view defined in 'myapp.views.UserView'. We pass request to the view's as_view() method to get a response. The APIRequestFactory is a part of the Django REST framework test library.