Introduction
They were interested in microservices. How can microservices use them for increased agility and scalability?
Microservices are architectural style and pattern structures which application as a collection of services. Services are highly maintainable, testable, loosely coupled, independently deployable, and precisely focused.
Also Microservices with Python3, flask, and Docker with the monolithic approach. Flask can be used to prototype and build microservices, to use Docker to host and deploy them. Also, check how to install flask in Ubuntu.
Requirements
Flask==1.0.2
pytest==4.6.2
flask-inputs==0.3.0
jsonschema==3.0.1
Flask is the most popular way to distribute a RESTful microservice in Python. Simple API working to make sure we’re doing it right. The micro in microframework means Flask aims to keep the core simple but extensible.
The framework gives you a comfortable defining endpoints, handling the request data, and building the HTTP responses. In addition, it has a built-in templating engine, which is very easy to use but just as easy to replace should you prefer another module.
Features
- Django style route definitions
- Simple, modular, microservices inspired architecture
- Dynamic, overridable resolution of Static / Template directories
Advantages of this plugin
- Allow Blueprint-defined template folders to override parent templates, rather than the other way around.
- Allow Blueprint-defined static folders to resolve from and override /static, rather than explain individual /static_module_name folders.
- Enable modularly, but the centralized definition of routes with a cleaner syntax so that you aren’t forced to hunt for @app.route() decorators or use the arcane blueprint syntax in complex projects.
- Allow you to drop-in/drop-out functionality sections at will, just bypassing the module’s name for portability, testing, and modularity.
Flask-MicroServices is not exceptionally complex.On the contrary, it is pretty tiny– 200-ish lines of code, but it can bring a high level of reasonability to the way you write your Flask applications.
Installing modules for Microservices with Python3
In this tutorial we are using python3
# dnf install python3-pip -y
Installing of the modules
# cat requirements.txt
Flask==1.0.2
pytest==4.6.2
flask-inputs==0.3.0
jsonschema==3.0.1
Allow port http on firewalld
So Allow port from the firewall with the command indicated below.
# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
Now create a test script for testing Microservices with Python3
The following code is as follows.
# cat astonmini.py
#!/usr/bin/python3
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def index() -> str:
return jsonify({"message": "If it doest work, then what does works?"})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
Give permission to execute and test the script
Also execute the commands below for testing.
# python3 astonmini.py