Welcome to our Library Management System API Web Application! This web application is designed to streamline the management of library resources, providing a comprehensive set of endpoints to handle various book-related operations. Whether you're adding new books, deleting outdated entries, searching for specific titles, or updating existing details, our API has you covered.
- Library Management System API
- Frontend
- Documentation
- fetchRequest Function
- createLi Function
- createLis Function
- displayBooky Function
- listAllBooks Function
- listBooksByCategory Function
- insertBook Function
- deleteBook Function
- updateBook Function
- searchBooks Function
- listBooksBySelectedCategory Function
- formInput Function
- displayBooks Function
- updatesearch Function
- Usage
- Documentation
This web application is designed to streamline the management of library resources, providing a comprehensive set of endpoints to handle various book-related operations. Whether you're adding new books, deleting outdated entries, searching for specific titles, or updating existing details, our API has you covered.
-
Book Management:
Adding Books: Easily insert new books into the library database, ensuring accurate and up-to-date information.
Deleting Books: Remove outdated or unnecessary books from the library inventory with a simple deletion process.
Searching Books: Efficiently search for specific titles or topics within the library's extensive collection.
Updating Book Details: Keep book information current by updating details such as title, author, genre, and more. -
Library Statistics:
Total Number of Books: Retrieve insights into the overall size of the library collection.
Categories: Explore the diverse range of book genres available in the library.
User Counts: Obtain statistics on library usage, including user counts for a better understanding of engagement.
-
List All Books: Call listAllBooks('all-books') to display a comprehensive list of all available books on page load.
-
Manage Books by Category: Utilize listBooksByCategory to fetch and display books based on specific categories.
-
Insert New Books: Add fresh additions to the library by employing the insertBook function.
-
Delete Books: Remove unwanted or obsolete books using the deleteBook function.
-
Update Book Information: Keep book details accurate with the updateBook function.
-
Search for Books: Use the searchBooks function to perform searches based on your specific criteria.
-
List Books by Selected Category: Enhance user experience by implementing listBooksBySelectedCategory to filter books by a chosen category.
-
Explore Library Statistics: Dive into the library's statistical insights, including the total number of books, categories, and user counts.
The backend of the application is built using Python, Flask, and MySQL. The Flask application is configured to connect to a MySQL database, which stores information about the books in the library. The application provides a set of endpoints to perform various operations on the database, including adding, deleting, updating, and searching for books. The application also provides endpoints to retrieve statistics about the library, such as the total number of books, categories, and user counts.
The backend documentation provides an overview of the backend code for a library management system. The code includes functions for connecting to the database, creating API endpoints, and performing various operations on the database.
Directory: Backend
Make sure you have Python installed on your system. Then, create and activate a virtual environment.
python -m venv venv
venv\Scripts\activate
source venv/bin/activate
Install the required Python packages using the provided requirements.txt
file:
pip install -r requirements.txt
Set up your MySQL database by configuring the environment variables in a .env
file.
Specify the database user
, password
, host
, name
, and the default route
.
DATABASE_USER=your_database_user
DATABASE_PASSWORD=your_database_password
DATABASE_HOST=your_database_host
DATABASE_NAME=your_database_name
ROUTE_DEFAULT=/api/v1
Run the Flask application using the following command:
python app.py or flask run
The application will be accessible at http://127.0.0.1:5000/ by default.
- Route:
/api/v1
- Method:
GET
- Description: Welcome message for the books library system.
{
"success": true,
"status": 200,
"message": "Welcome to the books library system"
}
- Route:
/api/v1/status
- Method:
GET
- Description: Returns a status message confirming that the application is running.
{
"success": true,
"status": 200,
"message": [
{"request": true, "response": true},
{"Header1": "Value1", "Header2": "Value2"}
]
}
- Route:
/api/v1/stats
- Method:
GET
- Description: Returns statistics of the library management system.
{
"success": true,
"status": 200,
"message": [
{
"book": [
{
"total": 50,
"countByCategories": 5,
"categories": ["Fiction", "Non-Fiction"]
}
]
},
{
"user": [
{
"total": 100,
"verified": 80,
"unverified": 20
}
]
}
]
}
- Route:
/api/v1/insert
- Method:
POST
- Description: Adds a book to the library.
{
"title": "Sample Book",
"author": "John Doe",
"genre": "Fiction",
"isbn": "1234567890",
"year": 2022,
"synopsis": "A sample book synopsis.",
"copiesAvailable": 10
}
{
"success": true,
"status": 201,
"message": "The book has been added to the Library"
}
- Route:
/api/v1/delete
- Method:
DELETE
- Description: Deletes a book from the library.
- Example Request:
{
"isbnOrTitle": "1234567890"
}
{
"success": true,
"status": 201,
"message": "The book has been deleted"
}
- Route:
/api/v1/search
- Method:
GET
- Description: Searches for books in the library based on a query.
- Query Parameters:
query=
Search term
{
"success": true,
"status": 200,
"message": [
{
"id": 1,
"title": "Sample Book",
"author": "John Doe",
"genre": "Fiction",
"isbn": "1234567890",
"year": "2022",
"synopsis": "A sample book synopsis.",
"copiesAvailable": 10,
"dateAdded": "2022-01-01T12:00:00",
"dateModified": "2022-01-01T12:00:00"
}
],
"count": 1
}
- Route:
/api/v1/list
- Method:
GET
- Description: Retrieves a list of all books from the library.
{
"success": true,
"status": 200,
"message": [
{
"id": 1,
"title": "Sample Book",
"author": "John Doe",
"genre": "Fiction",
"isbn": "1234567890",
"year": "2022",
"synopsis": "A sample book synopsis.",
"copiesAvailable": 10,
"dateAdded": "2022-01-01T12:00:00",
"dateModified": "2022-01-01T12:00:00"
}
],
"count": 1
}
- Route:
/api/v1/list/category
- Method:
GET
- Description: Retrieves a list of books based on a specific genre.
- Query Parameters:
genre=
Book category
{
"success": true,
"status": 200,
"message": [
{
"id": 1,
"title": "Sample Book",
"author": "John Doe",
"genre": "Fiction",
"isbn": "1234567890",
"year": "2022",
"synopsis": "A sample book synopsis.",
"copiesAvailable": 10,
"dateAdded": "2022-01-01T12:00:00",
"dateModified": "2022-01-01T12:00:00"
}
],
"count": 1
}
- Route:
/api/v1/update
- Method:
PUT
- Description: Updates the details of a book in the library.
{
"title": "Updated Sample Book",
"author": "John Doe",
"genre": "Fiction",
"isbn": "1234567890",
"year": 2023,
"synopsis": "An updated sample book synopsis.",
"copiesAvailable": 5
}
{
"success": true,
"status": 201,
"message": "The book has been updated in the Library"
}
- Description: 404 Not Found
{
"success": false,
"status": 404,
"message": "Resource Not Found"
}
- Route:
/api/v1/register
- Method:
POST
- Description: Adds a user to the database.
{
"confirmed": false,
"confirmedOn": "Tue, 12 Dec 2023 14:22:36 GMT",
"dateCreated": "Sun, 10 Dec 2023 10:53:06 GMT",
"dateModified": "Tue, 12 Dec 2023 14:22:36 GMT",
"emailAddress": "xxxx@xxx.com",
"firstName": "Jhon",
"id": "692d0248fe3f40dda061e34f45e41b04",
"lastName": "Doe",
"location": "",
"middleName": "B",
"phoneNumber": "000-0XX-XXX-XXX",
"photos": null,
"role": "user",
"status": "inactive",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDI0NzczNTgsImlhdCI6MTcwMjM5MDk1OCwic3ViIjoiYnVnZW1hcnZpbkBvdXRsb29rLmNvbSJ9.mJp0HLS-u66s672qDGZmxjZmkiV92Ld-nRPoxZomnis"
}
{
"success": true,
"status": 201,
"message": "User created successfully"
}
- Route:
/api/v1/login
- Method:
GET
- Description: Login a user
Authorization: Bearer <token>
{
"username": "emailAddress | phoneNumber",
"password": "password"
}
{
"sucess": true,
"status": 200,
"message": "User logged in successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDI0NzczNTgsImlhdCI6MTcwMjM5MDk1OCwic3ViIjoiYnVnZW1hcnZpbkBvdXRsb29rLmNvbSJ9.mJp0HLS-u66s672qDGZmxjZmkiV92Ld-nRPoxZomnis"
}
- Route:
/api/v1/logout
- Method:
GET
- Description: Login a user
{
"sucess": true,
"status": 200,
"message": "User logged out successfully",
}
The frontend of the application is built using HTML, CSS, and JavaScript. The frontend code is designed to test and interact with the backend API from the Flask server, making fetch requests to the API endpoints to perform various operations on the library database. The frontend code also provides functions to display the results of the fetch requests in the browser.
The frontend documentation provides an overview of the frontend code for a library management system. The code includes functions for making fetch requests, creating and displaying list items, managing books, and interacting with a Flask server.
Directory: Frontend
This function makes a fetch request to the specified API endpoint with the given request type and JSON data.
Parameters:
path (string): The path for the API endpoint.
ReqType (string): The request type (e.g., GET, POST, PUT, DELETE).
jsonData (Object): The JSON data to be sent with the request.
Returns:
A Promise that resolves with the response data or rejects with an error.
This function creates a list item and appends it to the specified element.
Parameters:
id (string): The id of the element to append the list item to.
data (string): The text content of the list item.
Returns:
The appended list item element.
This function creates an HTML li element with information about a book.
Parameters:
data (Object): The data object containing book information.
Returns:
The created li element.
This function displays a list of books in the specified container element.
Parameters:
id (string): The ID of the container element.
books (Array): An array of book objects.
This function fetches and displays all books.
Parameters:
all (HTMLElement): The container element to display the books.
Returns:
A Promise that resolves with the response from the server.
This function fetches and displays books by category.
Parameters:
category (string): The category of books to fetch.
id (string): The ID of the element to display the books in.
Returns:
A Promise that resolves with the response from the server.
This function inserts a book into the library management system.
Returns:
A Promise that resolves with the response from the server in JSON format.
This function deletes a book from the library management system.
Returns:
A Promise that resolves with the response from the server.
This function updates a book in the library management system.
Returns:
A Promise that resolves with the response from the server.
This function performs a search for books based on the provided search query.
Returns:
A Promise that resolves with the response from the server.
This function lists books by the selected category.
Returns:
A Promise that resolves with the response from the server.
This function generates a form input element with pre-filled values based on the provided data.
Parameters:
data (Object): The data object containing the values for the form input fields.
Returns:
The generated form input element.
This function displays a list of books in the specified container element.
Parameters:
id (string): The ID of the container element.
books (Array): An array of book objects.
This function updates the search results based on the provided search query.
Returns:
A Promise that resolves with the response from the server.
- Call
listAllBooks('all-books')
to display all books on page load. - Use other functions like
listBooksByCategory
,insertBook
,deleteBook
,updateBook
,searchBooks
, andlistBooksBySelectedCategory
to interact with the library management system.