You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In starlette you can access request object in function decorated with the route decorator.
it seems very handy to be able to access middlewares etc,
is there a way in fastapi to do that using the provided get/post/options.... decorators?
same question for the ApiRouter.
It's pretty much what (I guess) you would expect. Declare it with a Starlette Request type and FastAPI will provide it:
fromfastapiimportFastAPIfromstarlette.requestsimportRequestapp=FastAPI()
@app.get("/")defread_root(request: Request):
query=notes.select() # Not sure where `notes` comes fromresults=awaitrequest.database.fetchall(query)
return {"Hello": results}
omg this rocks, I think my attempt at using the async postgresql will be
soon up!
Le ven. 1 févr. 2019 à 9:40 PM, Sebastián Ramírez <notifications@github.com>
a écrit :
Yes! It's not properly documented yet.
It's pretty much what (I guess) you would expect. Declare it with a
Starlette Request type and FastAPI will provide it:
from fastapi import FastAPIfrom starlette.requests import Request
app = FastAPI()
@app.get("/")def read_root(request: Request):
query = notes.select() # Not sure where `notes` comes from
results = await request.database.fetchall(query)
return {"Hello": results}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#19 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABDZPmZuQ3qnbVexqJaiAs2SnnbZdAuKks5vJKZBgaJpZM4ae_ub>
.
In starlette you can access request object in function decorated with the route decorator.
it seems very handy to be able to access middlewares etc,
is there a way in fastapi to do that using the provided get/post/options.... decorators?
same question for the ApiRouter.
The text was updated successfully, but these errors were encountered: