Coverage for docs_src/additional_status_codes/tutorial001_an_py310.py: 100%
15 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 typing import Annotated 1abc
3from fastapi import Body, FastAPI, status 1abc
4from fastapi.responses import JSONResponse 1abc
6app = FastAPI() 1abc
8items = {"foo": {"name": "Fighters", "size": 6}, "bar": {"name": "Tenders", "size": 3}} 1abc
11@app.put("/items/{item_id}") 1abc
12async def upsert_item( 1abc
13 item_id: str,
14 name: Annotated[str | None, Body()] = None,
15 size: Annotated[int | None, Body()] = None,
16):
17 if item_id in items: 1abc
18 item = items[item_id] 1abc
19 item["name"] = name 1abc
20 item["size"] = size 1abc
21 return item 1abc
22 else:
23 item = {"name": name, "size": size} 1abc
24 items[item_id] = item 1abc
25 return JSONResponse(status_code=status.HTTP_201_CREATED, content=item) 1abc