Skip to content

Commit 7de3b7e

Browse files
committed
Improvements and fixes to fastapi example
1 parent 5af7535 commit 7de3b7e

File tree

4 files changed

+239
-111
lines changed

4 files changed

+239
-111
lines changed

03-fastapi/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# FastAPI + Jinja2 Example
22

3-
Warning: Python support in Workers is experimental and things will break. This
4-
example is meant for reference only right now; you should be prepared to update
5-
your code between now and official release time as APIs may change.
6-
73
## How to Run
84

95
First ensure that `uv` is installed:

03-fastapi/src/worker.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@
55
environment = jinja2.Environment()
66
template = environment.from_string("Hello, {{ name }}!")
77

8-
9-
class Default(WorkerEntrypoint):
10-
async def fetch(self, request):
11-
import asgi
12-
13-
return await asgi.fetch(app, request.js_object, self.env)
14-
15-
168
app = FastAPI()
179

18-
1910
@app.get("/")
2011
async def root():
2112
message = "This is an example of FastAPI with Jinja2 - go to /hi/<name> to see a template rendered"
@@ -33,3 +24,9 @@ async def env(req: Request):
3324
env = req.scope["env"]
3425
message = f"Here is an example of getting an environment variable: {env.MESSAGE}"
3526
return {"message": message}
27+
28+
class Default(WorkerEntrypoint):
29+
async def fetch(self, request):
30+
import asgi
31+
32+
return await asgi.fetch(app, request.js_object, self.env)

0 commit comments

Comments
 (0)