-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (31 loc) · 988 Bytes
/
Copy pathmain.py
File metadata and controls
36 lines (31 loc) · 988 Bytes
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
from fastapi import FastAPI
from fastapi.responses import HTMLResponse, FileResponse
import random
app = FastAPI()
@app.get("/favicon.svg", response_class=FileResponse)
def favicon():
return "favicon.svg"
@app.get("/api/random")
def get_random_number():
return {"number": random.randint(1, 100)}
@app.get("/", response_class=HTMLResponse)
def read_root():
return """
<html>
<head>
<title>Simple App</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
</head>
<body>
<h1>Hello World, the random number is: <span id="random-number"></span></h1>
include Favicon
<script>
fetch('/api/random')
.then(response => response.json())
.then(data => {
document.getElementById('random-number').innerText = data.number;
});
</script>
</body>
</html>
"""