docs_src/dependencies/tutorial008e_an_py310.py
raw| 1 | from typing import Annotated |
| 2 | |
| 3 | from fastapi import Depends, FastAPI |
| 4 | |
| 5 | app = FastAPI() |
| 6 | |
| 7 | |
| 8 | def get_username(): |
| 9 | try: |
| 10 | yield "Rick" |
| 11 | finally: |
| 12 | print("Cleanup up before response is sent") |
| 13 | |
| 14 | |
| 15 | @app.get("/users/me") |
| 16 | def get_user_me(username: Annotated[str, Depends(get_username, scope="function")]): |
| 17 | return username |