pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
339 B
16 lines
339 B
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
|
|
|