Add app.py with mock api implementation

This commit is contained in:
Ceda EI 2020-12-19 18:49:11 +05:30
parent fcd74cbbfb
commit e055e70778
1 changed files with 24 additions and 0 deletions

24
app.py Normal file
View File

@ -0,0 +1,24 @@
import json
from flask import Flask, jsonify, request
app = Flask(__name__)
with open("data.json") as f:
data = json.load(f)
@app.route('/all/')
def get_all():
return jsonify(data)
@app.route('/data/<data_id>', methods=["POST"])
def set_data_point(data_id):
try:
value = request.json["value"]
except KeyError:
return jsonify({"success": False}), 400
data[data_id] = value
with open("data.json", "w") as f:
json.dump(data, f)
return jsonify({"success": True})