Back to articles
Health Checks in Production APIs: Beyond Returning 200 OK

Health Checks in Production APIs: Beyond Returning 200 OK

via Dev.to WebdevYoung Gao

Health Checks in Production APIs: Beyond Returning 200 OK The /health endpoint that just returns { "status": "ok" } is useless. It tells you the process is running. It does not tell you if the app can actually serve requests. Liveness vs Readiness Liveness : Is the process alive? If not, restart it. Readiness : Can it handle traffic? If not, stop sending requests. app . get ( " /health/live " , ( _ , res ) => res . status ( 200 ). json ({ status : " alive " })); app . get ( " /health/ready " , async ( _ , res ) => { const checks = await Promise . allSettled ([ checkDatabase (), checkRedis (), checkExternalAPI (), ]); const results = { database : checks [ 0 ]. status === " fulfilled " , redis : checks [ 1 ]. status === " fulfilled " , externalAPI : checks [ 2 ]. status === " fulfilled " , }; const healthy = Object . values ( results ). every ( Boolean ); res . status ( healthy ? 200 : 503 ). json ({ status : healthy ? " ready " : " not ready " , checks : results }); }); Dependency Check

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles