A simple RESTful API for managing books, built with Flask and SQLAlchemy.
- Create, read, update, and delete books
- Unit tests for all endpoints
- Python 3.6+
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/lainceline/lain_example_api.git cd lain_example_api -
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On macOS/Linux:
source venv/bin/activate
-
-
Install the required packages:
pip install -r requirements.txt
-
Initialize the database:
flask shell
-
In the Python shell, create the tables:
from app import db db.create_all() exit()
-
Start the Flask development server:
flask run
-
The API will be accessible at
http://127.0.0.1:5000/.
GET /books: Get a list of all booksPOST /books: Add a new bookGET /books/<int:book_id>: Get a book by IDPUT /books/<int:book_id>: Update a book by IDDELETE /books/<int:book_id>: Delete a book by ID
-
Ensure you are in the virtual environment.
-
Run the tests using
unittest:python -m unittest discover -s tests
lain_example_api/
│
├── app.py # Main application file
├── book_model.py # SQLAlchemy Book model
├── database.py # Database operations
├── requirements.txt # Python packages
├── resources/
│ └── book_resource.py # API resource definitions
├── tests/
│ └── test_api.py # Unit tests
└── README.md # Project documentation
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.