-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.py
More file actions
55 lines (44 loc) · 1.02 KB
/
Server.py
File metadata and controls
55 lines (44 loc) · 1.02 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
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/")
def _root():
"""
root dir of server
:return:str
"""
return "This is root"
@app.route('/user')
def user_info():
"""
get data from GET request and check length
:return:json
"""
json = request.get_json()
if len(json['name']) == 0:
return "Invalid name"
return jsonify(json['name'])
@app.route('/user/<name>')
def user_name(name):
"""
:param name:
:return:
"""
return jsonify(name)
@app.route('/save', methods=['POST'])
def save_note():
"""
get data from POST method and return json response
:return:json
"""
json = request.get_json()
title = json['title']
disc = json['description']
response = {
"status": "success",
"message": "note added successfully",
"Your note": "" + title + " : " + disc
}
return jsonify(response)
# running in local machine
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)