Coding a generic pagination class
Right now, the table that persists the notifications in the database has just a few rows. However, after we start working with our API encapsulated in a microservice in a real-life production environment, we will have hundreds of notifications, and therefore, we will have to deal with large result sets. We don't want an HTTP GET
request to retrieve 1,000 notifications in a single call. Thus, we will create a generic pagination class and we will use it to easily specify how we want large results sets to be split into individual pages of data.
First, we will compose and send HTTP POST
requests to create nine notifications that belong to one of the notification categories we have created: Information
. This way, we will have a total of 12 messages persisted in the database. We had three messages and we add nine more. The code file for the sample is included in the restful_python_2_03_01
folder, in the Flask01/cmd309.txt
file:
http POST ":5000/service/notifications...