Flask stands out as one of Python’s most popular web frameworks. Designed for versatility and ease of use, Flask offers a robust starting point for crafting web apps.
By the following posts, I will use Flask to
create a series of Python web applications from simple app (Hello Zack)
develop microservices applications (order and user), deploy using Docker compose
Create Python API gateway application to
Integrate with Consul for service discovery and register
Enable logging with ELK, monitoring with Prometheus & Grafana
Last I will create Kubernetes manifast for K8S deployment.
I will skip ArgoCD and Github Action as I had done similar posts before.
Get started with Flask env and simple app
I will skip the installation for Docker and python3 as those can be found via the official Docker and Python website.
In the application Python code, I will import the Flask class from the flask module. Flask is a micro web framework written in Python. The Flask class is used to create a Flask application instance, which will be used to handle incoming web requests and route them to the appropriate functions in our code.
Create “user” and “order” flask microservice apps
Now I will move to create 2 microservice applications with Flask.
In design I will import the Flask class and jsonify function to create a Flask application instance, define a route (/orders) and a corresponding function (get_orders) to handle requests to that route, then return a JSON response with order details. Same design for user.py as well.
Create Dockerfile for containirztion
Build, tag and run it using docker-compose
Conclusion
Now we can use Python flask to create a simple web application and containerized it using Dockerfile
In the next post, I will see how to use API Gateway and Consul for more features to this Python applications.