A lightweight Flask REST API for managing books without a database. Book data is stored in a local JSON file so the project remains simple and easy to run locally.
- CRUD operations for books
- JSON file-based persistence
- Swagger/OpenAPI documentation
- environment-driven configuration
- easy Postman testing
- Python 3
- Flask 3.x
- Flasgger
- Gunicorn for production serving
app.py- Flask app and API endpointsrequirements.txt- project dependenciesdata/books.json- local storage for booksBooks_LocalHost.postman_collection.json- Postman requeststests/test_app.py- API regression tests
- Clone or download this repository.
- Open a terminal in the project folder.
- Create and activate a virtual environment (optional but recommended):
python -m venv .venv
.venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtpython app.pyThe app runs by default on:
Swagger UI is available at:
You can override the default file storage and runtime settings with environment variables:
set BOOKS_DATA_FILE=C:\path\to\books.json
set HOST=0.0.0.0
set PORT=5000If not provided, the app uses:
data/books.json0.0.0.05000
Returns all books.
Creates a new book.
Example body:
{
"name": "Clean Code",
"price": 399,
"isbn": 102,
"author": "Robert C. Martin"
}Returns a single book matched by ISBN.
Replaces an existing book by ISBN.
Updates selected fields on an existing book without replacing the full record.
Example body:
{
"price": 450,
"author": "Updated Author"
}Deletes a book by ISBN.
- Open Postman.
- Import
Books_LocalHost.postman_collection.json. - Ensure the collection uses the local server URL
http://127.0.0.1:5000. - Run the requests in order or individually.
npm install -g newman
newman run Books_LocalHost.postman_collection.json- No database is used in this project.
- Data persists in the JSON file configured by
BOOKS_DATA_FILE. - For production, it is recommended to move this to a proper database and add authentication/validation as needed.