Building RESTful APIs with DRF
DRF is an extension of Django for developing and deploying RESTful APIs. In Chapter 3, Setting Up the Development and Runtime Environment, we installed DRF through pip
as a Python package, and in this section, we’ll apply DRF to develop a RESTful API for our sample application. DRF provides us with these functionalities:
- The actual API that clients can access through one or more endpoints
- Serializers that collaborate with Django ORM to transform data from data source to JSON and the other way around
- A set of pre-defined views to quickly and easily create API endpoints for CRUD operations
If we transpose this to Django and zoom in on the Django file structure, we’ll see that DRF is primarily about these standard Django files:
models.py
: Containing the data model for our APIviews.py
: Containing the API viewset and specifications for CRUD operationsurls.py
: Containing the endpoints for our API views ...