Skip to main content
EasyBackendBuild

Build a Basic Health Check Route

Add a `GET /health` route to the FastAPI app in `main.py`. The route must return a JSON response with two fields: `status` (always the string `"ok"`) and `uptime_seconds` (the number of whole seconds since the app start...

What you will practice

PythonREST APIs / RoutesFastAPIHTTP Fundamentals

Requirements

  • Register a `GET /health` route on the existing FastAPI `app` instance in `main.py`.
  • The route must respond with HTTP status code 200.
  • The response body must be JSON with exactly two keys: `status` and `uptime_seconds`.
  • `status` must always be the string `"ok"`.
  • `uptime_seconds` must be a Python `int` (not a `float`, not a `bool`).
  • `uptime_seconds` must reflect whole seconds since the process started — it must grow monotonically across requests, never reset to 0 on a fresh request.

Starter files

main.pyEditable starter

What the judge checks

  • Runs in the python environment with the python-pytest runner.
  • Uses a 5000ms judge budget.
  • Behavior rules include: Health Route Returns 200, Response Status Ok, Uptime Seconds Is Integer, Uptime Grows Monotonically.

Constraints

  • Use FastAPI for route definition (the app object is already created in `main.py`).
  • Response body must be valid JSON.
  • `uptime_seconds` must be a Python `int`, not a `float`.

Example behavior

Input
GET /health (immediately after the app starts)
Output
200 OK
{"status": "ok", "uptime_seconds": 0}

Right at boot, uptime hasn't accumulated a full second yet.

Input
GET /health (10 seconds after the app starts)
Output
200 OK
{"status": "ok", "uptime_seconds": 10}

Uptime grows as the process keeps running. Always returns whole seconds, never fractional.

Follow-up

How would you extend `/health` to also report the status of each external dependency (database, Redis, etc.) without making the route slow under normal traffic?