In this article, we shall see how one can make a simple single-page Flask application that uses a free education API called Gutendex to create a book search.
But before that, let’s look at Gutendex - what is Gutendex? Gutendex is a JSON web API for Project Gutenberg ebook data. An online library of free electronic books or eBooks, Project Gutenberg, was, in fact, the first provider of these eBooks. Michael Hart, the founder of Project Gutenberg, invented eBooks in 1971, and his memory continues to inspire the creation of eBooks and related content.
Pre-requisites for this project:
Python Modules
Front End: Bootstrap 5 https://getbootstrap.com/ More information on the API: http://gutendex.com/ More information on Project Gutenberg: https://www.gutenberg.org/
Concepts:
Download the Flask cheatsheet from here: https://www.youngwonks.com/flask-cheatsheet.pdf
STEP 1: Setting up the project
STEP 2: Testing the API
Now we are mainly interested in the values of 5 keys for our website
a. Title: book['title']
b. Image: book [ 'formats'][ 'image/jpeg']
c. Text: book [ 'formats'][ 'text/plain; charset=utf-8']
d. Authors: book['authors']
Step 3: Creating the Flask app
STEP 4: Getting the data and rendering it on the page
STEP 5: Developing the front end with bootstrap
Replace the contents of home.html with the bootstrap5 started template provided at: https://getbootstrap.com/docs/5.0/getting-started/introduction/
STEP 6: Developing the front end as you please Use the documentation in bootstrap to create your desired page. For this tutorial, we are going to keep it simple. We have the following elements:
You can find the carousel sample at: https://getbootstrap.com/docs/5.0/components/card/. You can find the form group sample at: https://getbootstrap.com/docs/5.0/forms/input-group/.
STEP 7: Final Step: Using Jinja2 to render the data on the html page
Add the name for the input element.
Voila! Now, run the program and visit http://127.0.01:5000.