A simple and lightweight Flask RESTful API for managing a science library, including books.
Built with Python and MongoDB, designed for learning clean, modular API development.
- π CRUD Operations - Create, Read, Update, Delete books
- π§ Categorize materials by scientific fields (Physics, Chemistry, Biology, etc.)
- π Search by title, author, or topic
- β‘ Lightweight, modular, and easy to extend
- ποΈ MongoDB - NoSQL database for flexible data storage
- π RESTful - Standard HTTP methods and JSON responses
| Layer | Technology |
|---|---|
| Language | Python 3.10+ |
| Framework | Flask |
| Database | MongoDB |
| API Type | RESTful |
| Data Format | JSON |
| ODM | PyMongo |
| Method | Endpoint | Description | Request Body | Response | Status |
|---|---|---|---|---|---|
POST |
/api/v1/books/manage/add |
Add new book | {"id": 1,"title": "A Brief History of Time","author": "Stephen Hawking","year": 1988,"isbn": "9780553380163","subject": "Physics","copies_available": 5,"publisher": "Bantam Books"} |
{"message": "Book added", "id": "123"} |
β Done |
PUT |
/api/v1/books/manage/update?id=<id> |
Update book | {"title": "New Title"} |
{"message": "Book updated"} |
π§ In Progress |
DELETE |
/api/v1/books/manage/delete?book_id=<id> |
Delete book | None | {"message": "Book deleted"} |
β Done |
| Method | Endpoint | Description | Parameters | Response | Status |
|---|---|---|---|---|---|
GET |
/api/v1/books/filter/view_all |
Get all books | None | [{book1}, {book2}, ...] |
β Done |
GET |
/api/v1/books/filter/search |
Search books | ?author=name&subject=physics |
[{matching_books}] |
β Done |
GET |
/api/v1/books/filter/id/<id> |
Get book by ID | /<id> |
{id_book} |
β Done |
GET |
/api/v1/books/filter/author/<author> |
Get books by author | /<author> |
[{author_books}] |
β Done |
GET |
/api/v1/books/filter/subject/<subject> |
Get books by subject | /<subject> |
[{subject_books}] |
β Done |
GET |
/api/v1/books/filter/isbn/<isbn> |
Get books by isbn | /<isbn> |
[{isbn_books}] |
β Done |
GET |
/api/v1/books/filter/publisher/<publisher> |
Get books by publisher | /<publisher> |
[{publisher_books}] |
β Done |
GET |
/api/v1/books/filter/title/<titler> |
Get books by title | /<title> |
[{title_books}] |
β Done |
GET |
/api/v1/books/filter/year/<year> |
Get books by year | /<year> |
[{year_books}] |
β Done |
GET |
/api/v1/books/filter/copies/<copies> |
Get books by no. of copies | /<copies> |
[{number_copies_books}] |
β Done |
| Method | Endpoint | Description | Parameters | Response | Status |
|---|---|---|---|---|---|
GET |
/api/v1/books/stats/total-copies |
Get total books count | None | {"total_books": 150} |
β Done |
GET |
/api/v1/books/stats/total-copies-by-subject |
Get books count by subject | None | {"Physics": 50, "Chemistry": 30} |
β Done |
| Method | Endpoint | Description | Parameters | Response | Status |
|---|---|---|---|---|---|
GET |
/api/v1/books/user/signup |
register a new account | ?username=<username>&passsword=<password> |
{"status":"successfully register"} |
π§ In Progress |
POST |
/api/v1/books/user/signin |
signin account | ?username=<username>&passsword=<password> |
{"status":"successfully signin"} |
π§ In Progress |
| Functionality | Description | Progress |
|---|---|---|
| generate secret key | generate secret key for the token | β Done |
| generate super key | generate super key for the token | β Done |
| register new account | create new account | π§ In Progress |
| sigin account | sigin account | π§ In Progress |
| Functionality | Description | Progress |
|---|---|---|
| Logging | record the activity of each function for debuggging purposes | β Done |
| Unit Testing | Test if the unit is working on what instructed to do | β Done |
| Github Action Workflow | Do testing on when pushing project into Github Repository | β Done |
http://127.0.0.1:5000/home or http://127.0.0.1:5000/
bash curl -X POST http://127.0.0.1:5000/api/v1/books/add \
-H "Content-Type: application/json" \
-d '{
"title": "A Brief History of Time",
"author": "Stephen Hawking",
"year": 1988,
"isbn": "9780553380163",
"subject": "Physics",
"copies_available": 5,
"publisher": "Bantam Books"
}'{
"science_library": [
{
"id": "<generated id>",
"title": "A Brief History of Time",
"author": "Stephen Hawking",
"year": 1988,
"isbn": "9780553380163",
"subject": "Physics",
"copies_available": 5,
"publisher": "Bantam Books"
}
]
}{
"user":[
{
"id": "<generated id>",
"username": "user123",
"password": "<encrypted password>",
"fullname": "Tom B. Green",
"first_name": "Tom",
"middle_name": "Barnacle",
"last_name": "Green",
"tokens": {
"super_key":"<generated token>",
"secret_keys": {
"name": "key",
"key": "<generated key>",
"exp": "<generated expiration date>"
}
}
}
]
}git clone https://github.com/yourusername/science-library-api.git cd science-library-api
python -m venv venv
venv\Scripts\activate
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
MONGODB_URI = mongodb://localhost:27017/science_library
sudo systemctl start mongod # Linux
brew services start mongodb/brew/mongodb-community
python src/app.py
sudo apt-get install mongodb
brew tap mongodb/brew
brew install mongodb-community
Windows - Download from https://www.mongodb.com/try/download/community
sudo systemctl start mongod
sudo systemctl enable mongod
brew services start mongodb/brew/mongodb-community
net start MongoDB
mongosh
show dbs
use science_library
show collections
Author: John Jayson B. De Leon
Github: savjaylade84
Email: deleonjohnjayson@gmail.com | deleonjohnjayson@proton.me
Portfolio: Jisun