from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import FastAPI, Request, HTTPException
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def read_root(request: Request):
return templates.TemplateResponse("hello.html", {"request": request})
@app.get('/data')
async def get_data(ticker: str, date: str, qty: int):
try:
response = "Bye"
return response
except:
return {"Timeout" : "Error"}
@app.get('/stocks')
async def get_stocks_data():
try:
response = "Hello"
return response
except:
return {"Timeout" : "Error"}