Taking advantage of pagination
Our database has a few rows for each of the tables that persist the models we have defined. However, after we start working with our API in a real-life production environment, we will have thousands of player scores, players, and games—although the ESRB ratings will still be few in number. We definitely have to prepare our API to deal with large result sets. Luckily, we can take advantage of the pagination features available in Django REST framework to make it easy to specify how we want large result sets to be split into individual pages of data.
First, we will write commands to compose and send HTTP POST
requests to create 10 games that belong to one of the ESRB ratings we have created: T (Teen)
. This way, we will have a total of 12 games persisted in the database. We had two games and we add 10 more. The code file for the sample is included in the restful_python_2_07_01
folder, in the Django01/cmd/cmd705.txt
file:
http POST ":8000/games/" name='Heavy Fire...