This repo includes the code for creating the backend of a digital library. It has functionalities needed by the backend of a digital library app, like getting the book data from "google book API", adding new books to database, changing the status of the book, and rating it.
Note: the API key is removed from server.py
and create_book_table.py
.
- PostgreSQL for database
- FastAPI for backend
- Docker for containerization
for each book, the following info is fetched from google book API and stored in the database.
- ID (auto increment)
- volume_id (unique key)
- title
- authors
- thumbnail
- state (0: completed, 1: in progress, 2: wishlist)
- rating
make sure Docker is installed on your system
run the following command to create postgres and adminer container. Adminer container provides UI for interacting with the DB.
docker compose up -d
Adminer is accessible at (http://localhost:8080/)
.
install the requirements for the python env.
pip install -r requirements.txt
In order to test the API, run server.py
and type this address in browser http://localhost:8000/docs#/default
. Then you can interactively use and test the API.
In the following, I will explain different components of the API calls.
This endpoint will query all the data from the database and return the result in json format.
This end point gets the data in the following format and adds it to the databse.
{
"id": 0,
"volume_id": "string",
"title": "string",
"authors": "string",
"thumbnail": "string",
"state": 0,
"rating": 0
}
this endpoint gets the ISBN of the book as input and gets the books information from google book API and stores it in the database.
this endpoint is used for updating the rating of the book. The input should be in the following format.
{
"volume_id": "string",
"new_rating": 0
}
This end point is used for updating the book state to finished, in progress, or wishlist. The input should be in the following format
{
"volume_id": "string",
"new_state": 0
}
I will create a user interface using react so that the user can use it as a digital library.