Skip to content

Commit c1562b3

Browse files
Improvements and fixes to fastapi example (#39)
* Improvements and fixes to fastapi example * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5af7535 commit c1562b3

File tree

5 files changed

+241
-111
lines changed

5 files changed

+241
-111
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: astral-sh/setup-uv@v4
2020

2121
- name: Set up Python
22-
run: uv python install
22+
run: uv python install 3.13
2323

2424
- name: Install dependencies
2525
run: |

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: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
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

1810

@@ -33,3 +25,10 @@ async def env(req: Request):
3325
env = req.scope["env"]
3426
message = f"Here is an example of getting an environment variable: {env.MESSAGE}"
3527
return {"message": message}
28+
29+
30+
class Default(WorkerEntrypoint):
31+
async def fetch(self, request):
32+
import asgi
33+
34+
return await asgi.fetch(app, request.js_object, self.env)

0 commit comments

Comments
 (0)