# Add a /health endpoint to your local server Source: https://portlivo.com/guides/health-check-endpoint · Updated 2026-12-04 A health endpoint is a URL like localhost:3000/health that answers “I’m up” without rendering a page or needing a login. Scripts, Docker, load balancers and menu bar tools use it to tell a running server from a stuck one. It takes a few lines in any framework. **In short:** Add a route that returns status 200 and a tiny JSON body, such as `{"status":"ok"}`, with no login and no slow work. Rails 7.1+ already has `/up` and Laravel 11 has `/up`. Test it with `curl -fsS http://localhost:3000/health`: it prints the body when the server is healthy and fails otherwise. Portlivo can then check that path for every server and colour it green or red. ## What a good health endpoint does - Returns `200` when healthy and `503` when not. Tools read the status code, not the text. - Answers fast, in milliseconds: no page rendering, no external API calls. - Needs no login and sets no cookies, so a plain `curl` works. - Keeps its body small, like `{"status":"ok"}`, and never includes secrets or config. Common paths are `/health`, `/healthz`, `/api/health` and `/up`. Any works; pick one and use it in every project. ## Express and Next.js Express: ``` app.get("/health", (req, res) => { res.json({ status: "ok" }); }); ``` Next.js App Router, in `app/api/health/route.ts` (served at `/api/health`): ``` export function GET() { return Response.json({ status: "ok" }); } ``` Since Next.js 15, `GET` handlers run on every request. On Next.js 14 and older they could be cached at build time; add `export const dynamic = "force-dynamic"` there. ## Flask, FastAPI and Django Flask: ``` @app.get("/health") def health(): return {"status": "ok"} ``` FastAPI: ``` @app.get("/health") def health(): return {"status": "ok"} ``` Django, in `urls.py`: ``` from django.http import JsonResponse from django.urls import path urlpatterns = [ path("health/", lambda request: JsonResponse({"status": "ok"})), # ...your other routes ] ``` ## Rails and Laravel already have one - Rails 7.1 and later: new apps include `get "up" => "rails/health#show"` in `config/routes.rb`. It returns 200 when the app booted. - Laravel 11 and later: `bootstrap/app.php` sets `health: '/up'` in `withRouting`. - Spring Boot: add the Actuator dependency and use `/actuator/health`. ## Test it on localhost ``` curl -fsS http://localhost:3000/health ``` `-f` makes curl fail on 4xx and 5xx, `-sS` hides the progress bar but keeps errors. To see the status code and time only: ``` curl -s -o /dev/null -w "%{http_code} in %{time_total}s\n" http://localhost:3000/health ``` `Connection refused` means the server isn’t running or is on another port: see [localhost refused to connect](https://portlivo.com/guides/localhost-refused-to-connect-mac). A `404` means the route isn’t registered at that path. ## Should it check the database? Two kinds of check answer different questions. Keep `/health` simple (“the process is up”) and add a second endpoint if you need more: | Endpoint | Answers | Checks | | --- | --- | --- | | `/health` (liveness) | Is the process alive? | Nothing beyond answering | | `/ready` (readiness) | Can it serve real requests? | Database, cache, queue: return 503 if one is down | Keep database checks to a cheap query like `SELECT 1` with a short timeout, so the health check never becomes the slow part. ## Use it in Docker Compose ``` services: web: healthcheck: test: ["CMD", "curl", "-fsS", "http://localhost:3000/health"] interval: 10s timeout: 2s retries: 3 ``` The image needs `curl` for this. With `depends_on: { web: { condition: service_healthy } }`, other services wait until it passes. ## The one-click way: Portlivo Portlivo checks every web server on your Mac while its menu or window is open, and colours each one by the answer: green for 2xx, orange for 4xx, red for 5xx, with the response time. Set the path to `/health`, `/up` or any other in the inspector, and it checks that instead of `/`. So when one of five local servers breaks, you see which one without opening five tabs. More on [health checks](https://portlivo.com/features/health-checks). ## Questions people ask **What should a health check endpoint return?** Status 200 and a small body such as `{"status":"ok"}` when healthy, and 503 when it can’t serve requests. Tools look at the status code. **/health, /healthz or /up?** Any of them. `/healthz` comes from Kubernetes, `/up` is the Rails and Laravel default. Use the one your framework already has, or `/health`. **Will a health check fill my server logs?** Each check is a request, so it shows in the log. Check at a sensible interval (every 10 to 30 seconds), or filter the path out of your request logger.