API
Call Flask api in the same server
1. Install requests package
$ pip install requests
2. Add threaded in app.run()
if __name__ == '__main__':
app.run(threaded=True,debug=True)
2.1 Request example
@app.route('/datasets/ROI', methods=['GET'])
def list_ROI():
query = "select relname as table from pg_stat_user_tables where schemaname = 'roi';"
rows = conn.query(query).getresult()
datasets = []
for row in rows:
datasets.append(row[0])
return jsonify({'datasets': datasets})
@app.route('/test', methods=['GET'])
def test():
r = requests.get("http://127.0.0.1:5566/datasets/ROI")
return r.text
$ curl '127.0.0.1:5566/datasets/ROI'
{
"datasets": [
"taxi",
"test"
]
}
$ curl '127.0.0.1:5566/test'
{
"datasets": [
"taxi",
"test"
]
}