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
Binary file added GuruChandra/__pycache__/day2.cpython-313.pyc
Binary file not shown.
Binary file added GuruChandra/__pycache__/day4.cpython-313.pyc
Binary file not shown.
Binary file added GuruChandra/__pycache__/day5.cpython-313.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions GuruChandra/day4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

# Structure of the incoming JSON data
class UserData(BaseModel):
name: str
age: int

@app.get("/")
def home():
return {"message": "Day 4: API Testing with POSTMAN"}

@app.post("/user-info")
def create_user(user: UserData):
# This function accepts a JSON object matching the UserData model
return {
"status": "Success",
"received_data": {
"name": user.name,
"age": user.age
},
"message": f"Hello {user.name}, you are {user.age} years old!"
}
30 changes: 30 additions & 0 deletions GuruChandra/day5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from fastapi import FastAPI
from fastapi.responses import JSONResponse

app = FastAPI(title="Calculator API")

@app.get("/")
def home():
return {"message": "Welcome to Calculator API"}

@app.get("/add")
def add(a: float, b: float):
result = a + b
return {"operation": "addition", "a": a, "b": b, "result": result}

@app.get("/subtract")
def subtract(a: float, b: float):
result = a - b
return {"operation": "subtraction", "a": a, "b": b, "result": result}

@app.get("/multiply")
def multiply(a: float, b: float):
result = a * b
return {"operation": "multiplication", "a": a, "b": b, "result": result}

@app.get("/divide")
def divide(a: float, b: float):
if b == 0:
return JSONResponse(status_code=400, content={"error": "Cannot divide by zero"})
result = a / b
return {"operation": "division", "a": a, "b": b, "result": result}