Files
2026-09-08 17:39:51 +00:00

26 lines
582 B
Python

from fastapi import FastAPI
import json
app = FastAPI()
@app.get("/")
def home():
return {"message": "Welcome to DemoTel Product Catalog"}
@app.get("/products")
def get_products():
with open("products.json", "r") as file:
products = json.load(file)
return products
@app.get("/products/{productid}")
def get_product(productid: str):
with open("products.json", "r") as file:
products = json.load(file)
for product in products:
if product["productid"] == productid:
return product
return {"error": "Product not found"}