-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflaskapi.py
More file actions
33 lines (28 loc) · 945 Bytes
/
Copy pathflaskapi.py
File metadata and controls
33 lines (28 loc) · 945 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
31
32
33
import flask
from flask import request
app = flask.Flask(__name__)
app.config["DEBUG"] = True
serverData = []
@app.route('/', methods=['GET'])
def home():
return '''
<h1>Devsnest FLASK API</h1>
<ul>
<li>Add a string here: /add/string<br></li>
<li>Concat all the submitted strings: <url>/concat</li>
<ul>
'''
@app.route('/add', methods=['POST'])
@app.route('/add/<string:ip_str>', methods=['GET', 'POST'])
def addStringUsingGet(ip_str=None):
if request.method == "GET":
serverData.append(ip_str)
return 'The string {} has been saved in the server!'.format(serverData[-1])
elif request.method == "POST":
req_data = request.get_json(force=True)
serverData.append(req_data['string'])
return 'The string {} has been saved in the server!'.format(serverData[-1])
@app.route('/concat', methods=['GET'])
def concatString():
return ' '.join(serverData)
app.run()