Skip to content

This repository contains Python backend files for a library website built using Flask, SQLite, REST API and Data Structures.

Notifications You must be signed in to change notification settings

niranjana1997/Library-Flask-API

Repository files navigation

Library Flask API

This repository contains Python backend files for a library website built using Flask, SQLite, REST API and Data Structures.

  • Tools Used: DB Browser for SQLite, Postman, Visual Studio Code, Github Desktop
  • Libraries used: flask, sqlite3, flask_sqlalchemy, sqlalchemy
  • Data Structures Used: Linked List, Binary Search Tree, Stack, Queue, Hash Table
  1. DB Browser for SQLite: Allows the users to view the database via a graphical user interface. It is used to create, design, and edit database files compatible with SQLite.
  2. Postman: An API platform for building and using APIs.
  3. Flask: Micro web framework for creating APIs in Python. It is a middleware that is between the python application and the server.
  4. SQLite3: file-based SQL database used to integrate the SQLite database with Python.
  5. SQLAlchemy: Facilitates the communication between Python programs and databases.
  6. Flask-SQLAlchemy: Flask extension that makes using SQLAlchemy with Flask easier, providing you tools and methods to interact with your database in your Flask applications through SQLAlchemy.
  7. Object-Relational Mapping (ORM): Technique that lets you query and manipulate data from a database using an object-oriented paradigm.

Installation

  1. A virtual environment "venv" is created by the following command:

python3 -m venv venv

  1. The "venv" virtual environment is activated by the command (macOS):

. venv/bin/activate

  1. To install Flask:

pip install flask

  1. To install flask_sqlalchemy:

pip install flask_sqlalchemy

  1. To install sqlite3:

pip install pysqlite3

In the command line, to generate the database

  1. python
  2. from server import db,app
  3. app.app_context().push()
  4. db.create_all()
  5. exit()

Output of the application

  1. Author Table Values:

image

  1. Book Table values:

image

Output of REST API functions:

  1. POST - Add Author to Database
    { "fname":"Joanne", "lname":"Rowling", "country":"United Kingdom" }

image

  1. GET - Get Authors in Descending Order (Data Structure Used: Linked List)

image

  1. GET - Get Authors in Ascending Order (Data Structure Used: Linked List)

image

  1. GET - Get One Author by ID (Data Structure Used: Linked List)

User ID: 11

image

User ID: 22

image

  1. DELETE - Delete Author by ID

User ID: 10

image

image

User ID: 22

image

  1. GET - Get One Book by ID (Data Structure Used: Tree - Binary Search Tree Algorithm)

Book ID: 1

image

Book ID: 10

image

  1. GET - Get Book's Preface's ASCII value (Data Structure Used: Queue)

image

  1. POST - Add Book to Database
    { "title":"Harry Potter and the Deathly Hallows", "total_pages": 759, "rating": 4.62, "isbn": "9788893814560", "published_date": "2007-07-21", "preface": "Harry has been burdened with a dark, dangerous and seemingly impossible task: that of locating and destroying Voldemort's remaining Horcruxes. Never has Harry felt so alone, or faced a future so full of shadows. But Harry must somehow find within himself the strength to complete the task he has been given. He must leave the warmth, safety and companionship of The Burrow and follow without fear or hesitation the inexorable path laid out for him..." }

image

  1. DELETE - Delete last 5 Books (Data Structure Used: Stack)

Test Case 1: When 9 Books are present in the Database:

image

image

Test Case 2: When 4 Books are present in the Database

image

image

Test Case 3: When the Book Database is empty

image

image

Releases

No releases published

Packages

No packages published

Languages