-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
167 lines (132 loc) · 2.62 KB
/
Copy pathmain.py
File metadata and controls
167 lines (132 loc) · 2.62 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class User(BaseModel):
id: int
name: str
age: int
email: str
profession: str
phone: str
@app.post("/user")
def create_user(user: User):
print(user)
try:
return {
"message": "User Created Successfully",
"status": "success",
"data": user
}
except Exception as e:
return {
"message": str(e),
"status": "error",
"data": None
}
# @app.get("/user/{id}")
# def get_id(id: str):
# return {
# "id": id,
# }
# # Get Method
# @app.get("/")
# def get_method():
# return {"message": "Talha Rana AI Engineer"}
# # Put Method
# @app.put("/")
# def put_method():
# return {"message": "Talha Rana AI Engineer"}
# # Post Method
# @app.post("/")
# def post_method():
# return {"message": "Talha Rana AI Engineer"}
# # Delete Method
# @app.delete("/")
# def delete_method():
# return {"message": "Talha Rana AI Engineer"}
@app.get("/")
def get_method():
return {"message": "Talha Rana AI Engineer"}
data = [
{
"id": 1,
"name": "Shahjahan",
"age": 4,
"email": "talharana@gmail.com",
"phone": "03001234567"
},
{
"id": 2,
"name": "Talha Rana",
"age": 33,
"email": "talharana@gmail.com",
"phone": "03001234567"
},
{
"id": 3,
"name": "Ali Rana",
"age": 25,
"email": "talharana@gmail.com",
"phone": "03001234567"
},
{
"id": 4,
"name": "Danyal Rana",
"age": 27,
"email": "talharana@gmail.com",
"phone": "03001234567"
},
]
# @app.get("/login")
# def login():
# return {
# "data": data,
# "message": "Talha Rana AI Engineer",
# "status": "success",
# }
# @app.get("/login/{id}")
# def login(id):
# try:
# return {
# "id": id,
# "data": [],
# "message": "Login Successful",
# "status": "success",
# }
# print("Login Successful", data)
# except Exception as e:
# return {
# # "data": [],
# "message": "Login Failed",
# "status": 500,
# "error": str(e)
# }
# dynamic parameters in route
# @app.get("/login/{id}/{name}/{age}")
# def login(id, name, age):
# try:
# return {
# "id" : id,
# "name" : name,
# "age" :age
# }
# except Exception as e:
# return {
# "message": "Login Failed",
# "status": 500,
# "error": str(e)
# }
# @app.get("/login/{id}/{name}/{age}")
# def login(id, name, age):
# print(id, name, age)
# return {
# "id": id,
# "name": name,
# "age": age
# }
# @app.get("/user")
# def users(q):
# return {
# "query": q
# "name":
# }