-
First Check
Commit to Help
Example CodeThere is a full gist with example code here, but see description first. DescriptionI am trying to get FastAPI working in cloudflare workers + Pyodide. I have a custom asgi server to adapt between our runtime notion of We can do: from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/hello")
async def root(req: Request, x: int = 0):
env = req.scope["env"]
return {"message": "Hello World", "SECRET_KEY": env.OPENAI_API_KEY}but it would be nice to be able to say something like: from fastapi import FastAPI, Request
from mini_asgi_server import Environment
app = FastAPI()
@app.get("/hello")
async def root(env: Environment, x: int = 0):
return {"message": "Hello World", "SECRET_KEY": env.OPENAI_API_KEY}where somehow FastAPI could be told to get
I was hoping for something like a pytest fixture where I can create a new one like: @pytest.fixture
def environment(request: Request) -> Environment:
return request.scope["env"]Operating SystemOther Operating System DetailsPyodide FastAPI Version0.110.0 Pydantic Version2.6.3 Python Version4.12 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I think you can achieve this with a dependency: Then in your route: |
Beta Was this translation helpful? Give feedback.
I think you can achieve this with a dependency:
Then in your route: