This repository showcases FormaServe’s training capabilities and provides a simple web-service application.
This project is a Flask web service application that interfaces with the Chinook SQLite database. It provides endpoints to retrieve information about tracks and employees from the database and includes custom error handling for pages not found.
This will run on the IFS of the IBM i. Requires python and sqlite open-source packages installed.
It requires a copy of the SQLite sample database chinook which can be found in the data directory. If you require a fresh copy of the SQLite sample database it can be found here
- Provides a web-service application
- Provides four endpoints for employees & tracks
Clone this repository to your local machine.
git clone https://github.com/FormaServe/python-webservice.git
It is advised to check-out & run the section on virtual environments with python before proceeding with the install of this app.
Install the necessary dependencies
pip install flask jsonify
URL: /employee/int:employee_id
Method: GET
Description: Retrieves a specific employee by their EmployeeId.
Response: JSON object representing the employee, or a 404 error if not found.
URL: /employees
Method: GET
Description: Retrieves all employees from the employees table.
Response: JSON array of employee objects.
URL: /track/int:track_id
Method: GET
Description: Retrieves a specific track by its TrackId.
Response: JSON object representing the track, or a 404 error if not found.
URL: /tracks
Method: GET
Description: Retrieves all tracks from the tracks table.
Response: JSON array of track objects.
Insure that you use PIP to install the following packages (pip install bottle etc).
pip install flask jsonify
Start the server by running;
python server.py
then call the various endpoints as documented above.
As with all python projects, it is recommended to run this application in a virtual environment. Follow the instructions below to get started.
Use the venv module to create a virtual environment inside the project folder. Run the following command:
# Run the Python command to create a virtual environment in the current directory
python -m venv --system-site-packages .venv
Replace .venv with your preferred name for the virtual environment.
To activate the virtual environment.
source .venv/bin/activate
When you’re done working in the virtual environment, deactivate it:
deactivate
Remember to activate it whenever you work on your project. 😊
The application includes custom error handling for 404 Not Found errors.
When an endpoint is not found, the application returns a custom JSON response indicating the error.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
- FormaServe Systems Ltd - All work - FormaServe
- Andy Youens - FormaServe Systems Ltd 1990 - All rights reserved.
- Nick Youens - FormaServe Systems Ltd 1990 - All rights reserved.
- Jane Youens - FormaServe Systems Ltd 1990 - All rights reserved.