-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (28 loc) · 855 Bytes
/
main.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
40
41
42
43
from typing import Union
from fastapi import FastAPI
from models import Item,Student
app = FastAPI()
students_data = [
{
'name':"ulugbek",
'age':21,
'university':'TSUE',
'is_uzbek':True
}
]
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
@app.post("items/create/")
def create_item(item_id: int, item_name: str, item_price: float):
return {"item_name": item_name, "item_price": item_price}
@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
return {"item_name": item.name, "item_id": item_id}
@app.post("/students/register/")
def register_student(student:Student):
students_data.append(student)
return f'{student.name} added'