This is a simple Flask-based REST API application that interacts with a database to manage data related to people. The application provides endpoints to fetch, create, update, and delete records of people.
-
- GET /
- GET /getAllData
- GET /fetchData
- GET /getData/int:id
- PUT /editData/int:id
- DELETE /deleteData/int:id
This is a simple Flask-based REST API that allows users to manage people data (like name, height, mass, hair color, etc.) stored in a database. It supports CRUD operations (Create, Read, Update, Delete) for people records and can fetch data from an external API (SWAPI - Star Wars API) to populate the database.
First, clone the project repository to your local machine using Git:
git clone https://github.com/onirstudy/SWAPI.git
cd SWAPIFollow these steps to set up and run the Flask application on your local machine.
Before you begin, ensure you have the following installed:
- Python 3.x
- Flask
- SQLAlchemy
- Requests
To install the dependencies, run:
pip install -r requirements.txt python app.pypython crudtests.py- First Command (
pip install -r requirements.txt): This command installs all the dependencies listed in yourrequirements.txtfile. - Second Command (
python app.py): This starts the main application by executing theapp.pyfile. - Third Command (
python crudtests.py): This runs the tests defined in thecrudtests.pyfile.
Each command is enclosed in its own code block, making the instructions clear and easy to follow when viewed in the README.md file.
SWAPI is a simple Flask application that interacts with a database using SQLAlchemy to provide data from the Star Wars API.
The project directory structure is as follows:
📁SWAPI
📁.venv
├── app.py # Main Flask application
├── crudtests.py # Tests for CRUD functionality
├── deletetestcase.py # Tests for only deleteTestCase functionality
├── config.py # Configuration file for Flask and database
├── models.py # SQLAlchemy models for database interaction
├── templates/
│ └── index.html # HTML template for the index page
├── requirements.txt # Python dependencies
└── README.md # Documentation for the project
Once you have set up the application, you can run it locally by following these steps:
To run the Flask app, use the following command:
python app.pyHere are the full URLs for the endpoints:
(Renders the index.html page)
http://127.0.0.1:5000/(Fetches all data from the database)
http://127.0.0.1:5000/getAllData(Fetches data from the external API and stores it in the database)
http://127.0.0.1:5000/fetchData(Edits a person's data by their ID) (in The form of JSON)
http://127.0.0.1:5000/editData/<int:id>(Gets a person's data by their ID)
http://127.0.0.1:5000/getData/<int:id>(Deletes a person from the database by their ID)
http://127.0.0.1:5000/deleteData/<int:id>