Course
ai-dev-tools-zoomcamp
Question
Why does http://localhost:8000 return {"detail":"Not Found"} after I start my FastAPI backend?
Answer
Your FastAPI server is running correctly. The {"detail":"Not Found"} response means that the application has no endpoint defined for the root path (/).
Open the interactive API documentation instead:
http://localhost:8000/docs
Or call an endpoint that your application defines, for example:
http://localhost:8000/v1/household/state
If you want http://localhost:8000/ to show a response, add a root route to your FastAPI application:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def health_check():
return {"message": "API is running"}
FastAPI only responds to paths you define with route decorators such as @app.get("/"). When no matching route exists, it returns a 404 Not Found response with {"detail":"Not Found"}.
Checklist
Course
ai-dev-tools-zoomcamp
Question
Why does http://localhost:8000 return {"detail":"Not Found"} after I start my FastAPI backend?
Answer
Your FastAPI server is running correctly. The
{"detail":"Not Found"}response means that the application has no endpoint defined for the root path (/).Open the interactive API documentation instead:
Or call an endpoint that your application defines, for example:
If you want
http://localhost:8000/to show a response, add a root route to your FastAPI application:FastAPI only responds to paths you define with route decorators such as
@app.get("/"). When no matching route exists, it returns a404 Not Foundresponse with{"detail":"Not Found"}.Checklist