-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (26 loc) · 852 Bytes
/
main.py
File metadata and controls
33 lines (26 loc) · 852 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
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
posts: list[dict] = [
{
"id": 1,
"author": "Corey Schafer",
"title": "FastAPI is Awesome",
"content": "This framework is really easy to use and super fast.",
"date_posted": "April 20, 2025",
},
{
"id": 2,
"author": "Jane Doe",
"title": "Python is Great for Web Development",
"content": "Python is a great language for web development, and FastAPI makes it even better.",
"date_posted": "April 21, 2025",
},
]
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
@app.get("/posts", response_class=HTMLResponse, include_in_schema=False)
def home():
return f"<h1>{posts[0]['title']}</h1>"
@app.get("/api/posts")
def get_posts():
return posts