Request arguments

While sending a GET request to the base of the resource, our API currently sends all the Post objects in the database. This is acceptable if the number of objects is low or the number of people using the API is low. However, if either increases, the API will put a large amount of stress on the database. Much like the web interface, the API should be paginated as well.

In order to achieve this, our API will need to accept a GET query string parameter called page that specifies which page is to be loaded. Flask Restful provides a method to grab request data and parse it. If the required arguments aren't there, or the types don't match, Flask Restful will autocreate a JSON error message. In a new file in the api/blog/ folder ...

Get Mastering Flask Web Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.