mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-28 08:40:21 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
23 lines
506 B
Python
23 lines
506 B
Python
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Item(BaseModel):
|
|
id: str
|
|
value: str
|
|
|
|
|
|
class Message(BaseModel):
|
|
message: str
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/items/{item_id}", response_model=Item, responses={404: {"model": Message}})
|
|
async def read_item(item_id: str):
|
|
if item_id == "foo":
|
|
return {"id": "foo", "value": "there goes my hero"}
|
|
return JSONResponse(status_code=404, content={"message": "Item not found"})
|