Files
demotel-product-catalog/app.py
T
2026-09-08 17:23:22 +00:00

25 lines
564 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"}