-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
32 lines (27 loc) · 863 Bytes
/
api.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
import traceback
import uvicorn
from fastapi import FastAPI
from src.api_helper import *
app = FastAPI()
# === Application Main Endpoint
@app.get("/news")
def list_news(q: str = None, limit: int = 10):
"""
This single endpoint will server getting Top-Listings and Search functionality
for news aggregation APIs.
:param q: Search query in request url.
:param limit: Integer number to limit number of results to fetch from each dependent API.
:return: JSON response of aggregated results.
"""
try:
if q:
# call search endpoint
result = search_news(q, limit)
else:
# call news listing endpoint
result = get_news(limit)
return result
except:
return traceback.print_exc()
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)