-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlask_Testing.py
More file actions
40 lines (31 loc) · 806 Bytes
/
Copy pathFlask_Testing.py
File metadata and controls
40 lines (31 loc) · 806 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
34
35
36
37
38
39
import flask
from flask import jsonify
from functools import wraps
import os
app = flask.Flask(__name__)
def require_api_key(func):
@wraps(func)
def decorated_func(*arg, **kwargs):
provide_api_key = flask.request.headers.get('OPEC-Api-Key')
if provide_api_key == os.getenv('API_KEY'):
return func(*arg, **kwargs)
else:
return jsonify({'message':'Unauthorized'})
return decorated_func
@app.route('/')
def hello():
return 'Hello World'
@app.route('/test')
def DoTest():
return 'For Test'
@app.route('/api/getjson', methods=['GET'])
@require_api_key
def GetJson():
data = {
'name': 'John',
'age': 30,
'city': 'New York'
}
return jsonify(data)
if __name__ == '__main__':
app.run(debug=True)