All Coursera Quiz Answers

Module quiz: Securing an API in Django REST framework Quiz Answers

In this article i am gone to share Coursera Course: APIs by Meta Week 3 | Module quiz: Securing an API in Django REST framework Quiz Answers with you..

Also visit:  Module quiz: Django REST framework Quiz Answers

 

Module quiz: Securing an API in Django REST framework Quiz Answers

Question 1)
In what way can you validate the price field to not be less than 5 in a serializer? Choose all that apply.

  • By using a validation method
  • By using a validate_price_lt method

By adding this line of code in the serializer:

  • price = serializers.DecimalField(max_digits=6, decimal_places=2, min_value=5)

By adding

  • ‘price’: {‘min_value’: 2} in the extra_kwargs section
  • By using a validate method

 

Question 2)
How can you limit an API endpoint in such a way that only POST, PUT, PATCH and DELETE calls will be throttled, but GET calls will not be throttled? Choose all that apply.

  • This cannot be done
  • By writing a scoped throttle class and set it up in the settings.py file
  • By writing a custom throttle class and overriding the get_throttles method
  • By writing a custom throttle class and using it inside a @throttle_classes decorator.

Question 3)
For token-based authentication, you need to install the Djoser library because DRF doesn’t support such authentications by default.

  • True
  • False

Question 4)
How can you enable support for sorting the API output by two fields: age and gender?

  • By manually parsing the query string
  • By adding this line of code
  • ordering_fields=[‘age’,’gender’] in a class-based view
  • By adding this @ordering_fields([‘age’,’gender’]) above a function-based view
  • No code change is required. Just add ‘OrderingFilter’ in the settings.py file and DRF will process it automatically.

Question 5)
Which of the following are valid endpoints automatically created by Djoser?

  • /user/confirm/
  • /user/
  • /users/
  • /user/me/
  • /users/me/

Question 6)
You can manually expire a JWT access token any time you want.

  • True
  • False

Question 7)
How can you assign users to a user group? Choose all that apply.

  • Using Djoser library
  • By manually modifying the database records
  • By using the users.set() method in a Group object
  • By making a call to /users/groups endpoint
  • From the Django admin panel

Question 8)
Which of the following prefixes should you use to successfully authenticate a token using SimpleJWT library?

  • Auth Token
  • Bearer
  • Auth
  • Token

Question 9)
What happens when you blacklist a JWT refresh token?

  • It also blacklists the access token
  • It cannot be used to generate new access tokens anymore.
  • It expires
  • It blocks the user who bears this token
  • It cannot be used to generate new refresh tokens

Question 10)
Which of the following prefixes must you use with tokens to successfully authenticate an API call in plain DRF?

  • Bearer
  • Auth Token
  • Token
  • Auth

Question 11)
Which external package can you use to sanitize HTML tags from user input data?

  • Cleaner
  • Sanitizer
  • Bleach