-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
75 lines (60 loc) · 2.41 KB
/
App.py
File metadata and controls
75 lines (60 loc) · 2.41 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask, request, json, Response
from pymongo import MongoClient
import logging as log
from MongoAPI import MongoAPI
app = Flask(__name__)
@app.route('/')
def base():
return Response(response=json.dumps({"Status": "Arriba"}),
status=200,
mimetype='application/json')
@app.route('/mongodb', methods=['GET'])
def mongo_read():
data = request.json
if data is None or data == {}:
return Response(response=json.dumps({"Error": "Please provide connection information"}),
status=400,
mimetype='application/json')
obj1 = MongoAPI(data)
response = obj1.read()
return Response(response=json.dumps(response),
status=200,
mimetype='application/json')
@app.route('/mongodb', methods=['POST'])
def mongo_write():
data = request.json
if data is None or data == {} or 'Document' not in data:
return Response(response=json.dumps({"Error": "Please provide connection information"}),
status=400,
mimetype='application/json')
obj1 = MongoAPI(data)
response = obj1.write(data)
return Response(response=json.dumps(response),
status=200,
mimetype='application/json')
@app.route('/mongodb', methods=['PUT'])
def mongo_update():
data = request.json
if data is None or data == {} or 'Filter' not in data:
return Response(response=json.dumps({"Error": "Please provide connection information"}),
status=400,
mimetype='application/json')
obj1 = MongoAPI(data)
response = obj1.update()
return Response(response=json.dumps(response),
status=200,
mimetype='application/json')
@app.route('/mongodb', methods=['DELETE'])
def mongo_delete():
data = request.json
if data is None or data == {} or 'Filter' not in data:
return Response(response=json.dumps({"Error": "Please provide connection information"}),
status=400,
mimetype='application/json')
obj1 = MongoAPI(data)
response = obj1.delete(data)
return Response(response=json.dumps(response),
status=200,
mimetype='application/json')
if __name__ == '__main__':
app.run(debug=True, port=5001, host='0.0.0.0')