-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
124 lines (95 loc) · 2.93 KB
/
app.py
File metadata and controls
124 lines (95 loc) · 2.93 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from flask import Flask, render_template, make_response, jsonify, request
app = Flask(__name__)
PORT = 3200
# Get Method
DATA = {
"Employee": {
"Rohit":"Developer",
"Pratik":"Tester",
"Jack":"Manager",
"Milind":"Devops",
"Priyanka":"Fromtend",
},
"Locations":{
"Afourtech":"Pune",
"Opstree":"Delhi",
"Cloudera":"Banglore",
"Mindtree":"Mumbai",
"Spacetech":"Chennai",
},
"CICD":{
"AWS":"Codepipeline",
"Azure":"Azure Devops",
"OpenSource":"Jenkins",
"IBM":"Udeploy",
}
}
@app.route("/")
def home():
return "<h1 style='color:green'>This is root!</h1>"
@app.route('/home')
def hello_world():
return render_template('index.html')
@app.route("/qstr")
def qs():
if request.args:
req = request.args
res = {}
for key, value in req.items():
res[key] = value
res = make_response(jsonify(res), 200)
return res
res = make_response(jsonify({"error": "No Query String"}), 404)
return res
@app.route("/json")
def get_json():
res = make_response(jsonify(DATA), 200)
return res
@app.route("/json/<collection>/<member>")
def get_data(collection, member):
print("getting the value of %s in the collection %s"%(member,collection))
if collection in DATA:
member = DATA[collection].get(member)
if member:
res = make_response(jsonify({"res":member}), 200)
return res
res = make_response(jsonify({"error": "Not found"}), 404)
return res
res = make_response(jsonify({"error": "Not found"}), 404)
return res
# Post Method
@app.route("/json/<collection>", methods=["POST"])
def create_col(collection):
req = request.get_json()
if collection in DATA:
res = make_response(jsonify({"error": "Collection already exists"}), 400)
return res
DATA.update({collection: req})
res = make_response(jsonify({"message": "Collection created"}), 201)
return res
# Put Method
@app.route("/json/<collection>/<member>", methods=["PUT"])
def put_col_mem(collection,member):
req = request.get_json()
if collection in DATA:
if member:
print(req)
DATA[collection][member] = req["new"]
res = make_response(jsonify({"res":DATA[collection]}), 200)
return res
res = make_response(jsonify({"error": "Not found"}), 404)
return res
res = make_response(jsonify({"error": "Not found"}), 404)
return res
# Delete Method
@app.route("/json/<collection>", methods=["DELETE"])
def delete_col(collection):
if collection in DATA:
del DATA[collection]
res = make_response(jsonify(DATA), 200)
return res
res = make_response(jsonify({"error": "Collection not found"}), 404)
return res
if __name__ == "__main__":
print("Server running in port %s"%(PORT))
app.run(host='0.0.0.0', port=PORT)