Search⌘ K

Listing the Endpoint

Explore how to generate a reference list of API endpoints in a Django RESTful project using function-based views. Understand how to create an access point for these endpoints and test them with tools like Postman. This lesson helps you organize and verify your JWT authentication API endpoints for easier development and debugging.

Endpoints listing

After developing the JWT authentication API, it is best that we have a reference of its endpoints. That makes it easier to access the APIs endpoints without having to look them up in our app’s views.py file. We can generate a list of the endpoints using a function-based view, as shown below.

Python 3.8
# other imports ..
from rest_framework.decorators import api_view
from rest_framework.reverse import reverse
@api_view(['GET','HEAD'])
def api_root(request, format=None):
return Response({
'register': str(reverse('register', request=request, format=None)).replace("http://", "https://"),
'login': str(reverse('login', request=request, format=None)).replace("http://", "https://"),
'refresh-token': str(reverse('token_refresh', request=request, format=None)).replace("http://", "https://"),
'resend-verification-email': str(reverse('resend-verification-email', request=request, format=None)).replace("http://", "https://"),
'request-password-reset-email': str(reverse('request-password-reset-email', request=request, format=None)).replace("http://", "https://"),
'password-reset': str(reverse('password-reset', request=request, format=None)).replace("http://", "https://"),
'user-list': str(reverse('user-list', request=request, format=None)).replace("http://", "https://"),
'logout': str(reverse('logout', request=request, format=None)).replace("http://", "https://"),
})

In the code above:

  • The @api_view decorator takes a list of the HTTP methods that the view is allowed to respond
...