Coverage for docs_src/additional_responses/tutorial001.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi import FastAPI 1abcde
2from fastapi.responses import JSONResponse 1abcde
3from pydantic import BaseModel 1abcde
6class Item(BaseModel): 1abcde
7 id: str 1abcde
8 value: str 1abcde
11class Message(BaseModel): 1abcde
12 message: str 1abcde
15app = FastAPI() 1abcde
18@app.get("/items/{item_id}", response_model=Item, responses={404: {"model": Message}}) 1abcde
19async def read_item(item_id: str): 1abcde
20 if item_id == "foo": 1abcde
21 return {"id": "foo", "value": "there goes my hero"} 1abcde
22 return JSONResponse(status_code=404, content={"message": "Item not found"}) 1abcde