Ini adalah API RESTful sederhana untuk mengelola sistem perpustakaan, termasuk menangani operasi yang terkait dengan penulis dan buku. API ini memungkinkan pengguna untuk membuat, mengambil, memperbarui, dan menghapus penulis dan buku, serta mengambil semua buku yang terkait dengan penulis tertentu.
To run this application, you will need the following:
- Python 3.7+
- Flask
- Flask-SQLAlchemy
- MySQL database
- Pytest (for testing)
- MySQL client libraries (for Python)
-
Clone the repository:
git clone https://github.com/fajarpratamaputra/library_system.git
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On macOS and Linux:
source venv/bin/activate
-
-
Install MySQL:
-
Create a MySQL database:
-
Configure the application to use MySQL:
-
Open the
config.py
file:SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://library_user:your_password@localhost/library_db'
-
-
Initialize the database:
Run the following commands to create the necessary tables:flask db init flask db migrate -m "Initial migration" flask db upgrade
-
Start the Flask development server:
flask run
The application will be available at
http://127.0.0.1:5000
. -
Access the API:
GET /authors
GET /authors/{id}
POST /authors
PUT /authors/{id}
DELETE /authors/{id}
GET /authors/{id}/books
GET /books
GET /books/{id}
POST /books
PUT /books/{id}
DELETE /books/{id}
pytest tests/