-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·45 lines (37 loc) · 1.27 KB
/
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
39
40
41
42
43
44
45
import falcon
import json
import pathlib
from helper.log import logger
from src.middleware import HttpMethodValidator
from helper.utils import Constants
from src.query_builder import RunQuery
from src.db import DataBase
from falcon_swagger_ui import register_swaggerui_app
try:
logger.info("Connecting to Database")
database = DataBase(True)
logger.info(database)
logger.info("Connection successful")
except Exception as ex:
logger.info("Error " + str(ex))
raise Exception("Error Couldn't connect to %s Database" % (Constants.database.value))
class Home:
def on_get(self, req, resp):
logger.info("Sending response")
resp.status = falcon.HTTP_200
resp.body = json.dumps([{Constants.message.value: "server works"}], ensure_ascii=False)
SWAGGERUI_URL = '/swagger'
SCHEMA_URL = '/static/v1/swagger.json'
STATIC_PATH = pathlib.Path(__file__).parent / 'static'
home = Home()
search = RunQuery(database)
api = falcon.API(middleware=[HttpMethodValidator()])
api.add_static_route('/static', str(STATIC_PATH))
api.add_route('/', home)
api.add_route('/api/v1/embl/search', search)
page_title = 'EMBL search API doc'
register_swaggerui_app(
api, SWAGGERUI_URL, SCHEMA_URL,
page_title=page_title,
config={'supportedSubmitMethods': ['get'], }
)