-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-mini.py
39 lines (33 loc) · 941 Bytes
/
main-mini.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
33
34
35
36
37
38
39
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class UserData(BaseModel):
id: int
email: str
first_name: str
last_name: str
avatar: str
class SupportData(BaseModel):
url: str
text: str
class UserResponse(BaseModel):
data: UserData
support: SupportData
# Very bad code :(
@app.get("/api/users/2", response_model=UserResponse)
def get_user():
user_data = UserData(
id=2,
email="janet.weaver@reqres.in",
first_name="Janet",
last_name="Weaver",
avatar="https://reqres.in/img/faces/2-image.jpg"
)
support_data = SupportData(
url="https://reqres.in/#support-heading",
text="To keep ReqRes free, contributions towards server costs are appreciated!"
)
return UserResponse(data=user_data, support=support_data)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)