mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-26 15:51:02 -05:00
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
17 lines
339 B
Python
17 lines
339 B
Python
from fastapi import Depends, FastAPI
|
|
from typing_extensions import Annotated
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
def get_username():
|
|
try:
|
|
yield "Rick"
|
|
finally:
|
|
print("Cleanup up before response is sent")
|
|
|
|
|
|
@app.get("/users/me")
|
|
def get_user_me(username: Annotated[str, Depends(get_username, scope="function")]):
|
|
return username
|