Using REST APIs

You are working on a Puppy Store project which uses Django RESTful API. You have already added a unit test and you want to update the code to make it pass the test.

Which of these options will best fit the missing line of code, XXX, to perform the action given in the above context?

@api_view([‘GET’, ‘POST’])

def get_post_puppies(request):

if request.method == ‘GET’:

XXX

serializer = PuppySerializer(puppies, many=True)

return Response(serializer.data)

elif request.method == ‘POST’:

return Response({})

Options
  1. return Response(serializer.data)
  2. Puppy = puppies.objects.all()
  3. serializer = PuppySerializer(puppies, many=True)
  4. puppies = Puppy.objects.all()

Related Posts

Close Bitnami banner
Bitnami