diff --git a/GuruChandra/__pycache__/day2.cpython-313.pyc b/GuruChandra/__pycache__/day2.cpython-313.pyc new file mode 100644 index 00000000..38aa1e66 Binary files /dev/null and b/GuruChandra/__pycache__/day2.cpython-313.pyc differ diff --git a/GuruChandra/__pycache__/day4.cpython-313.pyc b/GuruChandra/__pycache__/day4.cpython-313.pyc new file mode 100644 index 00000000..582deabb Binary files /dev/null and b/GuruChandra/__pycache__/day4.cpython-313.pyc differ diff --git a/GuruChandra/__pycache__/day5.cpython-313.pyc b/GuruChandra/__pycache__/day5.cpython-313.pyc new file mode 100644 index 00000000..52ee3bb3 Binary files /dev/null and b/GuruChandra/__pycache__/day5.cpython-313.pyc differ diff --git a/GuruChandra/day4.py b/GuruChandra/day4.py new file mode 100644 index 00000000..7a3fa0c1 --- /dev/null +++ b/GuruChandra/day4.py @@ -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!" + } \ No newline at end of file diff --git a/GuruChandra/day5.py b/GuruChandra/day5.py new file mode 100644 index 00000000..c56a1d70 --- /dev/null +++ b/GuruChandra/day5.py @@ -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} \ No newline at end of file