From 78e2538813898b1dda2a32f33d142e89b1e6c3a8 Mon Sep 17 00:00:00 2001 From: Sandip Date: Sun, 29 Mar 2026 19:56:59 +0530 Subject: [PATCH] Added Day1 to Day5 FastAPI assignments --- Sandip/Day3.py | 8 +++++--- Sandip/Day5.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Sandip/Day5.py diff --git a/Sandip/Day3.py b/Sandip/Day3.py index bfdeb8e7..656495ee 100644 --- a/Sandip/Day3.py +++ b/Sandip/Day3.py @@ -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 diff --git a/Sandip/Day5.py b/Sandip/Day5.py new file mode 100644 index 00000000..261b4636 --- /dev/null +++ b/Sandip/Day5.py @@ -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} \ No newline at end of file