0
0
FastAPIframework~20 mins

Health check endpoints in FastAPI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Health Check Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the output of this FastAPI health check endpoint?
Consider this FastAPI endpoint code for a health check. What will the client receive when accessing /health?
FastAPI
from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
async def health_check():
    return {"status": "ok", "uptime": 12345}
A"status: ok, uptime: 12345"
B{"status": "ok", "uptime": 12345}
CHTTP 404 Not Found error
DAn empty JSON object {}
Attempts:
2 left
💡 Hint
Look at the return statement inside the endpoint function.
📝 Syntax
intermediate
1:30remaining
Which option correctly defines a FastAPI health check endpoint?
Select the code snippet that correctly defines a GET endpoint at /health returning JSON {"status": "healthy"}.
A
@app.get("/health")
async def health():
    return {"status": "healthy"}
B
app.get("/health")
async def health():
    return {"status": "healthy"}
C
@app.get("/health")
def health():
    print({"status": "healthy"})
D
@app.get("/health")
async def health():
    return "status: healthy"
Attempts:
2 left
💡 Hint
Remember the decorator syntax and that the function must return a dictionary for JSON.
state_output
advanced
1:30remaining
What is the response status code of this health check endpoint?
Given this FastAPI health check endpoint, what HTTP status code will the client receive?
FastAPI
from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
async def health_check():
    return {"status": "ok"}
A500
B404
C200
D302
Attempts:
2 left
💡 Hint
FastAPI returns 200 OK by default for successful GET requests.
🔧 Debug
advanced
2:00remaining
Why does this health check endpoint cause a runtime error?
Examine this FastAPI endpoint code. Why will it cause an error when accessed?
FastAPI
from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
async def health_check():
    return status: "ok"
ASyntaxError due to invalid return statement syntax
BTypeError because 'status' is undefined
CRuntimeError because async function is missing await
DNo error, returns JSON {"status": "ok"}
Attempts:
2 left
💡 Hint
Look carefully at the return statement syntax.
🧠 Conceptual
expert
2:00remaining
Which option best describes the purpose of a health check endpoint in FastAPI?
Choose the most accurate description of why a health check endpoint is used in FastAPI applications.
ATo log detailed error messages when the app crashes
BTo authenticate users before they access the main application features
CTo serve the main homepage content of the application
DTo provide a simple URL that external systems can call to verify the app is running and responsive
Attempts:
2 left
💡 Hint
Think about monitoring and uptime checks.