This project is a Flask microservice template that follows a layered architecture design pattern.
- It provides examples of the Controller, Service, Repository, and Client layers, along with a Model class.
- The application is built using default Flask modules without any extensions.
- All methods are defined using Python type hints for better readability and maintainability.
- Additionally, the project includes unit tests for each class to ensure proper functionality.
- Clone the repository:
git clone https://github.com/popclom/flask-microservice-template.git
cd flask-microservice-template- Set up the virtual environment and install dependencies:
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txtTo start the Flask microservice, run the following command:
python run.pyThe service will be accessible at http://localhost:5000.
To execute all unit tests for the application, use the following command:
python -m unittest discover -s testsRetrieve all users:
curl http://localhost:5000/usersRetrieve a specific user by ID (replace <user_id> with the actual ID):
curl http://localhost:5000/users/<user_id>Create a new user:
curl -X POST -H "Content-Type: application/json" -d '{"name": "John Doe", "email": "john@example.com"}' http://localhost:5000/usersUpdate an existing user by ID (replace <user_id> with the actual ID):
curl -X PUT -H "Content-Type: application/json" -d '{"name": "Updated Name", "email": "updated@example.com"}' http://localhost:5000/users/<user_id>Delete a user by ID (replace <user_id> with the actual ID):
curl -X DELETE http://localhost:5000/users/<user_id>Contributions are welcome! If you find any issues or want to add new features, please feel free to open a pull request.
This project is licensed under the MIT License.