Skip to main content
GET
/
api
/
health
Health Check
curl --request GET \
  --url https://api.example.com/api/health
{
  "status": "<string>",
  "time": {}
}

Overview

The health check endpoint provides a simple way to verify that the MediGuide server is running and can connect to the database. This endpoint is useful for monitoring, load balancer health checks, and deployment verification.

Endpoint

GET /api/health

Authentication

No authentication required. This is a public endpoint.

Response

status
string
Server status indicator. Returns "ok" when the server and database are operational.
time
object
Database timestamp object containing the current database server time.

Examples

curl http://localhost:3001/api/health

Success Response

{
  "status": "ok",
  "time": {
    "now": "2024-03-06T16:30:45.123Z"
  }
}

Error Response

{
  "status": "error",
  "error": "connection to database failed"
}

Implementation

From server.js:23-30:
server.js
app.get('/api/health', async (req, res) => {
  try {
    const { rows } = await pool.query('SELECT NOW()');
    return res.json({ status: 'ok', time: rows[0] });
  } catch (error) {
    return res.status(500).json({ status: 'error', error: error.message });
  }
});

Use Cases

Deployment Verification

Check that the server started successfully after deployment

Load Balancer Health Checks

Configure your load balancer to poll this endpoint

Monitoring

Set up automated monitoring to alert on downtime

Database Connection

Verify PostgreSQL connectivity without authentication

Build docs developers (and LLMs) love