Skip to main content

Overview

The health check endpoint provides a simple way to verify that the MediGuide API is running and can successfully connect to the database. This endpoint executes a basic database query to ensure connectivity and returns the current database timestamp.

Endpoint

curl -X GET https://api.mediguide.com/api/health

Request

method
string
required
GET
No request parameters are required for this endpoint.

Response

message
string
Status message indicating database connection status
time
object
Database timestamp object containing the current time from the database server

Success Response

200 - Success
{
  "message": "Database connected",
  "time": {
    "now": "2026-03-05T14:30:00.000Z"
  }
}

Error Response

500 - Internal Server Error
{
  "error": "Connection failed: database unavailable"
}

Implementation

The health check endpoint executes a simple SQL query to verify database connectivity:
app.get('/api/health', async (req, res) => {
  try {
    const result = await pool.query('SELECT NOW()');
    res.json({ message: 'Database connected', time: result.rows[0] });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

Use Cases

System Monitoring

Integrate this endpoint into your monitoring systems to track API uptime and database availability:
# Example monitoring script
*/5 * * * * curl -f https://api.mediguide.com/api/health || alert-system notify

Load Balancer Health Checks

Configure your load balancer to use this endpoint for health verification:
# Example load balancer configuration
healthCheck:
  path: /api/health
  interval: 30s
  timeout: 5s
  healthyThreshold: 2
  unhealthyThreshold: 3

Troubleshooting

When debugging connectivity issues, check this endpoint first to isolate whether the problem is with the API server or database:
  1. API returns 200 with timestamp - System is healthy
  2. API returns 500 with error - Database connection issue
  3. No response - API server is down or unreachable

CI/CD Pipeline Validation

Use this endpoint in deployment pipelines to verify successful deployment:
# Wait for service to be healthy after deployment
until curl -f https://api.mediguide.com/api/health; do
  echo "Waiting for API to be ready..."
  sleep 5
done
echo "Deployment successful!"

Build docs developers (and LLMs) love