- install flask
pip install flask
pip install flask_restful
- create api.py
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Product(Resource):
def get(self):
return{
'product': ['Ice cream',
'Chocolate',
'fruite']
}
api.add_resource(Product, '/')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=True)
- run the application
sudo python api.py
password: qianjiang
- stop the application: Ctrl+c