Working with routing and endpoints
We want to create an endpoint for the root of our web service to make it easy to browse the resource collections and resources provided by our web service with the browsable API feature and understand how everything works. Add the following code to the views.py file in the restful01/drones folder to declare the ApiRoot class as a subclass of the generics.GenericAPIView class. The code file for the sample is included in the hillar_django_restful_06_01 folder in the restful01/drones/views.py file:
class ApiRoot(generics.GenericAPIView):
name = 'api-root'
def get(self, request, *args, **kwargs):
return Response({
'drone-categories': reverse(DroneCategoryList.name, request=request),
'drones': reverse(DroneList.name, request=request),
'pilots': reverse(PilotList.name, request=request),
'competitions': reverse(CompetitionList.name, request=request)
}) The ApiRoot class is a subclass...