-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooks_app.py
42 lines (30 loc) · 937 Bytes
/
books_app.py
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
from flask import Flask, jsonify, request
from flask_swagger_ui import get_swaggerui_blueprint
import traceback
# from routes import request_api
from helper import *
from query_param_validation import *
app = Flask(__name__)
SWAGGER_URL = '/swagger'
API_URL = '/static/swagger.json'
SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "Python-Flask-REST-APIS"
}
)
app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)
@app.route("/books")
def hello():
try:
query_keys = request.args.keys()
if not validate_query_params(query_keys):
return jsonify(invalid_request_response()), 400
data = handle_request(request)
return jsonify(data), 200
except Exception as e:
print(traceback.format_exc())
return server_error_response(), 500
if __name__ == "__main__":
app.run(host='0.0.0.0')