3 changed files with 48 additions and 0 deletions
@ -0,0 +1,15 @@ |
|||||
|
from fastapi import Depends, FastAPI |
||||
|
|
||||
|
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: str = Depends(get_username, scope="function")): |
||||
|
return username |
||||
@ -0,0 +1,16 @@ |
|||||
|
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 |
||||
@ -0,0 +1,17 @@ |
|||||
|
from typing import Annotated |
||||
|
|
||||
|
from fastapi import Depends, FastAPI |
||||
|
|
||||
|
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 |
||||
Loading…
Reference in new issue