Django Rest framework
Creating your website's API might seem trivial using the services pattern we learned in Chapter 3, Models. However, real-world APIs need so much more functionality, such as web browsable documentation, authentication, serialization, and throttling, that you are better off using a toolkit such as Django Rest framework (DRF).
DRF is the most popular API toolkit for Django. It fits well with the Django architecture and reuses several familiar concepts such as generic views and model forms. Out of the box, the API is accessible and usable with a normal web browser, which makes testing and finding documentation easier for developers.
Improving the Public Posts API
Recall the services pattern example where we created a service to retrieve all the latest public posts? Now we shall reimplement it using the features provided by the DRF.
First, install DRF and add it to your INSTALLED_APPS
. Then, mention your permission model in settings.py
:
# Django Rest Framework settings REST_FRAMEWORK...