-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (25 loc) · 825 Bytes
/
app.py
File metadata and controls
30 lines (25 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, request, jsonify
from odh_local_storage import ODHLocalStorage
app = Flask(__name__)
db = ODHLocalStorage("odh_storage.db")
@app.route('/set_data', methods=['POST'])
def set_data():
data = request.get_json()
key = data.get('key')
value = data.get('value')
db.set_item(key, value)
return jsonify({'message': 'Data set successfully'})
@app.route('/get_data', methods=['GET'])
def get_data():
key = request.args.get('key')
value = db.get_item(key)
if value:
return jsonify({'value': value})
else:
return jsonify({'value': None, 'message': 'Key not found'})
@app.route('/clear_data', methods=['POST'])
def clear_data():
db.clear()
return jsonify({'message': 'Data cleared successfully'})
if __name__ == '__main__':
app.run(debug=True)