docs_src/handling_errors/tutorial001_py310.py
raw| 1 | from fastapi import FastAPI, HTTPException |
| 2 | |
| 3 | app = FastAPI() |
| 4 | |
| 5 | items = {"foo": "The Foo Wrestlers"} |
| 6 | |
| 7 | |
| 8 | @app.get("/items/{item_id}") |
| 9 | async def read_item(item_id: str): |
| 10 | if item_id not in items: |
| 11 | raise HTTPException(status_code=404, detail="Item not found") |
| 12 | return {"item": items[item_id]} |