From b0a935f81926393e12925ed2695e7b59871cfa7f Mon Sep 17 00:00:00 2001 From: FAQ Bot Date: Mon, 14 Sep 2026 13:20:43 +0000 Subject: [PATCH] NEW: Why does `http://localhost:8000` return `{ "detail": "Not Found" }` afte --- ...3_b7cb4e67d0_fastapi-root-404-not-found.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 _questions/ai-dev-tools-zoomcamp/02-development/003_b7cb4e67d0_fastapi-root-404-not-found.md diff --git a/_questions/ai-dev-tools-zoomcamp/02-development/003_b7cb4e67d0_fastapi-root-404-not-found.md b/_questions/ai-dev-tools-zoomcamp/02-development/003_b7cb4e67d0_fastapi-root-404-not-found.md new file mode 100644 index 00000000..1ab14fdf --- /dev/null +++ b/_questions/ai-dev-tools-zoomcamp/02-development/003_b7cb4e67d0_fastapi-root-404-not-found.md @@ -0,0 +1,26 @@ +--- +id: b7cb4e67d0 +question: 'Why does `http://localhost:8000` return `{ "detail": "Not Found" }` after + starting my FastAPI backend?' +sort_order: 3 +--- + +When you start a FastAPI server, FastAPI will only respond to routes you explicitly define. The `{"detail":"Not Found"}` response means your app has no endpoint registered for the root path (`/`), so FastAPI returns a `404`. + +To confirm the server is up, use the built-in docs or an existing endpoint: +- `http://localhost:8000/docs` +- `http://localhost:8000/` + +If you want `http://localhost:8000/` to return something, add a root route: + +```python +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +def health_check(): + return {"message": "API is running"} +``` + +Common cause: you’re hitting `/` but your main routes are under a prefix (e.g. `/v1/...`), or you haven’t added any `@app.get("/")` handler yet. \ No newline at end of file