Listing the Endpoint
Learn how to generate the endpoints list.
We'll cover the following...
We'll cover the following...
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.
Press + to interact
# other imports ..from rest_framework.decorators import api_viewfrom 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 when