/health?from fastapi import FastAPI app = FastAPI() @app.get("/health") async def health_check(): return {"status": "ok", "uptime": 12345}
The endpoint returns a dictionary with keys status and uptime. FastAPI automatically converts this dictionary to JSON in the response.
/health returning JSON {"status": "healthy"}.Option A uses the correct decorator @app.get("/health") and returns a dictionary, which FastAPI converts to JSON.
Option A misses the decorator symbol '@'. Option A returns None and prints instead of returning. Option A returns a string, not JSON.
from fastapi import FastAPI app = FastAPI() @app.get("/health") async def health_check(): return {"status": "ok"}
When a FastAPI endpoint returns a dictionary without specifying a status code, the default HTTP status code is 200 (OK).
from fastapi import FastAPI app = FastAPI() @app.get("/health") async def health_check(): return status: "ok"
The return statement uses invalid syntax. It should return a dictionary like {"status": "ok"}, but instead it uses a colon without braces, causing a SyntaxError.
A health check endpoint is a simple URL that monitoring tools or load balancers call to confirm the app is alive and working. It does not handle authentication or serve main content.