adhvaithprasad commited on
Commit
703e5e6
·
1 Parent(s): 456d207

tweaked the AP code

Browse files
Files changed (2) hide show
  1. app.py +20 -1
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,7 +1,26 @@
1
  from fastapi import FastAPI
 
 
 
 
 
 
 
 
 
 
2
 
3
  app = FastAPI()
4
 
5
- @app.get("/")
6
  def greet_json():
7
  return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+
4
+
5
+ class User_input(BaseModel):
6
+ operation:str
7
+ x:float
8
+ y:float
9
+
10
+ def calculate(operation, x, y):
11
+ return x/y
12
 
13
  app = FastAPI()
14
 
15
+ @app.get("/hello")
16
  def greet_json():
17
  return {"Hello": "World!"}
18
+
19
+
20
+ @app.post("/calculate")
21
+ def operate(input:User_input):
22
+ res= calculate(input.operation, input.x, input.y)
23
+ return res
24
+
25
+
26
+
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  fastapi
 
2
  uvicorn[standard]
 
1
  fastapi
2
+ pydantic
3
  uvicorn[standard]