Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Sandip/Day3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

app = FastAPI()

@app.get("/")
def home():
return {"message": "Server is running"}
# GET API
@app.get("/greet")
def greet(name: str):
return {"message": f"Hello, {name}!"}

# POST API
class User(BaseModel):
name: str
age: int
Expand Down
34 changes: 34 additions & 0 deletions Sandip/Day5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from fastapi import FastAPI

app = FastAPI()

# Home
@app.get("/")
def home():
return {"message": "Calculator API is running"}

# Add
@app.get("/add")
def add(a: int, b: int):
return {"result": a + b}

# Subtract
@app.get("/subtract")
def subtract(a: int, b: int):
return {"result": a - b}

# Multiply
@app.get("/multiply")
def multiply(a: int, b: int):
return {"result": a * b}

# Divide
@app.get("/divide")
def divide(a: int, b: int):
if b == 0:
return {"error": "Cannot divide by zero"}
return {"result": a / b}

@app.get("/square")
def square(n: int):
return {"result": n * n}