This commit is contained in:
dualtribesman 2025-12-16 21:09:33 +00:00 committed by GitHub
commit 657b33139f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import random
from typing import Annotated
from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from pydantic import AfterValidator
app = FastAPI()
@ -25,6 +25,10 @@ async def read_items(
):
if id:
item = data.get(id)
if item is None:
raise HTTPException(
status_code=404, detail=f"Item with id '{id}' not found"
)
else:
id, item = random.choice(list(data.items()))
return {"id": id, "name": item}