Microservices Classroomnotes 25/Dec/2021

Understanding API Views

  • Django Rest framework provides an API View class, which subclasses from Django’w View Class
  • In Django, The base view for creating APIs is APIView, But every API will have similar sort of code depending of what the API has to respond to
  • To return list of elemets from database
  • Get all the objects from the model
  • serialize the Elements into Json
  • Return the Response
  • Rather than us trying to do all of this Django restframework has handy API view
  • generics.ListAPIView: This view is derived from GenericAPIView and mixins.ListModelMixin which makes it extreemly easier to create a get for getting list of items
  • Now lets use ListCreateAPIView for our endpoint /Recipes/
  • Refer Here for the changes done
  • Now we have implemented the Publish and unpublish recipes and Get a specific recipe Refer Here for the changes

  • Exercise: Implement the delete API functionality (Soft Delete)

  • Refer Here for the Mixin and Refer Here for the API Views

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner