Skip to content

Improve FastAPI Python docs and adds frontend example. - #32662

Open
dom96 wants to merge 1 commit into
productionfrom
dominik/fastapi-better-docs
Open

Improve FastAPI Python docs and adds frontend example.#32662
dom96 wants to merge 1 commit into
productionfrom
dominik/fastapi-better-docs

Conversation

@dom96

@dom96 dom96 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Adjustments to our FastAPI docs to include better getting started section and example showing how to serve static files.

@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review

⚠️ 4 warnings, 💡 2 suggestions found in commit da398a9.

👉 Fix in your agent 👈
Fix the following review findings in PR #32662 (https://github.com/cloudflare/cloudflare-docs/pull/32662).

Before making changes, review each finding and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g. the fix requires disproportionate effort for minimal benefit,
  or the finding is factually incorrect), explain why
- If you need clarification before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

After triaging, follow this order:
1. Post a comment on this PR for any findings you are skipping, with the finding ID and your reasoning.
2. Then commit the fixes for the legitimate findings.

The comment must come before the commit — the bot reads PR comments when a new
push triggers a review, so skip comments posted after the push will be missed.

---

## Code Review

### Warnings (2)

#### CR-26cc790d8ba5 · Unencoded path used in asset URL
- **File:** `src/content/docs/workers/languages/python/packages/fastapi.mdx` line 143
- **Issue:** FastAPI’s `path` converter returns the URL-decoded value (e.g. `/my%20file.txt` becomes `my file.txt`). Interpolating it into `f"https://assets.local/{path}"` produces an invalid URL with a space, so `env.ASSETS.fetch(asset_url)` can fail for paths containing spaces or other encoded characters.
- **Fix:** Build the asset URL from pre-encoded data or re-encode the path, e.g. `from urllib.parse import quote` and use `f"https://assets.local/{quote(path, safe='/')}"`.

#### CR-6294191418dd · SPA fallback missing from static assets config
- **File:** `src/content/docs/workers/languages/python/packages/fastapi.mdx` line 94
- **Issue:** The section describes serving an SPA and compares the setup to FastAPI’s `app.frontend()`, but the `assets` block only sets `run_worker_first`. With this config, a request for a client-side route such as `/dashboard` reaches the catch-all handler, fetches a non-existent asset, and the assets binding returns 404 instead of falling back to `index.html`.
- **Fix:** Add `"not_found_handling": "single-page-application"` to the `assets` block so the assets binding serves `index.html` for missing paths.

### Suggestions (1)

#### CR-5f9236957b63 · Forward reference to app defined later
- **File:** `src/content/docs/workers/languages/python/packages/fastapi.mdx` line 128
- **Issue:** The `Default` class method calls `asgi.fetch(app, request, self.env)` while `app` is defined on line 132, after the class. Python resolves the name at call time, so this currently works, but it is fragile and confusing if the module is reorganized.
- **Fix:** Move the `app = FastAPI()` and route definitions above the `Default` Worker class so dependencies are defined before they are referenced.

---

## Style Guide Review

### Warnings (2)

#### SG-ccda99307cf5 · Use WranglerConfig component for Wrangler configuration
- **File:** `src/content/docs/workers/languages/python/packages/fastapi.mdx` line 47
- **Issue:** Raw ` ```jsonc ` block contains Wrangler keys (`name`, `main`, `compatibility_date`).
- **Fix:** Replace this block with the `<WranglerConfig>` component.

#### SG-66a5fdcc726a · Use WranglerConfig component for Wrangler configuration
- **File:** `src/content/docs/workers/languages/python/packages/fastapi.mdx` line 88
- **Issue:** Raw ` ```jsonc title="wrangler.jsonc" ` block contains Wrangler keys (`name`, `main`, `compatibility_date`).
- **Fix:** Replace this block with the `<WranglerConfig>` component.

### Suggestions (1)

#### SG-49e105ecc63b · Headings should use sentence case
- **File:** `src/content/docs/workers/languages/python/packages/fastapi.mdx` line 24
- **Issue:** Body heading `## Quick Start` uses title case.
- **Fix:** Change to `## Quick start`.

Code Review

This code review is in beta and may not always be helpful — use your judgment.

Warnings (2)
File Issue
workers/languages/python/packages/fastapi.mdx line 143 Unencoded path used in asset URL — FastAPI’s path converter returns the URL-decoded value (e.g. /my%20file.txt becomes my file.txt). Interpolating it into f"https://assets.local/{path}" produces an invalid URL with a space, so env.ASSETS.fetch(asset_url) can fail for paths containing spaces or other encoded characters. Fix: Build the asset URL from pre-encoded data or re-encode the path, e.g. from urllib.parse import quote and use f"https://assets.local/{quote(path, safe='/')}".
workers/languages/python/packages/fastapi.mdx line 94 SPA fallback missing from static assets config — The section describes serving an SPA and compares the setup to FastAPI’s app.frontend(), but the assets block only sets run_worker_first. With this config, a request for a client-side route such as /dashboard reaches the catch-all handler, fetches a non-existent asset, and the assets binding returns 404 instead of falling back to index.html. Fix: Add "not_found_handling": "single-page-application" to the assets block so the assets binding serves index.html for missing paths.
Suggestions (1)
File Issue
workers/languages/python/packages/fastapi.mdx line 128 Forward reference to app defined later — The Default class method calls asgi.fetch(app, request, self.env) while app is defined on line 132, after the class. Python resolves the name at call time, so this currently works, but it is fragile and confusing if the module is reorganized. Fix: Move the app = FastAPI() and route definitions above the Default Worker class so dependencies are defined before they are referenced.

Conventions

No convention issues found.

Style Guide Review

Warnings (2)
File Issue
workers/languages/python/packages/fastapi.mdx line 47 Use WranglerConfig component for Wrangler configuration — Raw ```jsonc block contains Wrangler keys (name, main, compatibility_date). Fix: Replace this block with the <WranglerConfig> component.
workers/languages/python/packages/fastapi.mdx line 88 Use WranglerConfig component for Wrangler configuration — Raw ```jsonc title="wrangler.jsonc" block contains Wrangler keys (name, main, compatibility_date). Fix: Replace this block with the <WranglerConfig> component.
Suggestions (1)
File Issue
workers/languages/python/packages/fastapi.mdx line 24 Headings should use sentence case — Body heading ## Quick Start uses title case. Fix: Change to ## Quick start.
Commands

Only codeowners can run commands. Post a comment with the command to trigger it.

Command Description
/review Runs a review now. Incremental if a prior review exists, full if not.
/full-review Re-reviews the entire PR diff from scratch, ignoring incremental history. Useful after a rebase, when you want a fresh review, or if the bot gets out of sync and reports issues that no longer exist.
/ignore-review-limit Permanently lifts the 2-review automatic limit for this PR. Future pushes will trigger reviews as normal.
/disable-auto-review Stops automatic reviews from triggering on future pushes to this PR. Codeowners can still run /review or /full-review manually.
/rebase Rebases the PR branch against production. On conflict, attempts to resolve automatically using AI. Stops with an explanation if confidence is not high enough.

@dom96
dom96 requested a review from hoodmane August 11, 2026 16:18
@dom96
dom96 requested a review from joesepi August 11, 2026 16:18
@github-actions github-actions Bot added the product:workers Related to Workers product label Aug 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/product-owners, @cloudflare/wrangler, @MattieTK, @cloudflare/dev-plat-leads, @vy-ton, @cloudflare/workers-runtime-1

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx Outdated
Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx Outdated
Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx Outdated
Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx Outdated
Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx Outdated
Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx Outdated
Comment thread src/content/docs/workers/languages/python/packages/fastapi.mdx
@dom96
dom96 force-pushed the dominik/fastapi-better-docs branch from 4611991 to 779f943 Compare August 12, 2026 14:41
@dom96
dom96 force-pushed the dominik/fastapi-better-docs branch from 779f943 to da398a9 Compare August 12, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:workers Related to Workers product size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants