-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyapi.py
More file actions
64 lines (49 loc) · 1.39 KB
/
myapi.py
File metadata and controls
64 lines (49 loc) · 1.39 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
from flask import Flask, request, jsonify
from flask.logging import create_logger
import logging, json
app = Flask(__name__)
LOG = create_logger(app)
LOG.setLevel(logging.INFO)
# Home
@app.route('/', methods=['GET'])
def home():
html = '''
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>API Test</title>
<meta name="description" content="API Test">
<meta name="author" content="Randall">
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>API Test</h1>
<p>We have added internal styles and will be attempting a full build.</p>
</body>
</html>
'''
mydata = 'Some test log info. Is this written to the log?'
LOG.info(f"My output: {mydata}")
return html
@app.route('/api/v1/test', methods=['GET','POST'])
def get_alert():
myheaders = request.headers()
request_data = request.get_json()
LOG.info(type(request_data))
result = json.dumps(request_data)
with open("data.txt", "a") as file:
file.write(result)
file.write("\n\n")
LOG.info(myheaders)
LOG.info("\n")
LOG.info(result)
msg = 'POST request succeeded.'
LOG.info(f"My output: {msg}")
return request_data
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True) # specify port=80