docs_src/events/tutorial001_py310.py
raw| 1 | from fastapi import FastAPI |
| 2 | |
| 3 | app = FastAPI() |
| 4 | |
| 5 | items = {} |
| 6 | |
| 7 | |
| 8 | @app.on_event("startup") |
| 9 | async def startup_event(): |
| 10 | items["foo"] = {"name": "Fighters"} |
| 11 | items["bar"] = {"name": "Tenders"} |
| 12 | |
| 13 | |
| 14 | @app.get("/items/{item_id}") |
| 15 | async def read_items(item_id: str): |
| 16 | return items[item_id] |