-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
23 lines (20 loc) · 747 Bytes
/
main.py
File metadata and controls
23 lines (20 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from schemas import TestRequest
from tester import run_test
from analyzer import analyze_results
app = FastAPI(title="API Reliability Analyzer")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/analyze")
async def analyze(test: TestRequest):
results = await run_test(
url=str(test.url),
duration=min(test.duration, 30),
rps=min(test.rps, 5)
)
analysis = analyze_results(results)
return analysis