Skip to main content

Overview

The health endpoint provides system status information, including the current environment and build version. This endpoint is useful for monitoring, load balancers, and deployment verification.

Endpoint

GET /api/health
Authentication
none
This endpoint does not require authentication

Request

Using Hono RPC Client

import { apiClient } from "@/lib/api/client"

const response = await apiClient.health.$get()
const { data } = await response.json()

console.log(data)
// {
//   message: "ok",
//   version: "1.0.0",
//   environment: "production"
// }

Using Fetch

const response = await fetch('https://your-domain.com/api/health', {
  method: 'GET',
})

const { data } = await response.json()

Using cURL

curl https://your-domain.com/api/health

Response

Success Response (200 OK)

data
object
required
The health check data object

Response Schema

interface HealthResponse {
  data: {
    message: string
    version: string
    environment: "local" | "development" | "test" | "staging" | "production"
  }
}

Example Response

{
  "data": {
    "message": "ok",
    "version": "1.0.0",
    "environment": "production"
  }
}

Implementation

The health endpoint is defined in api/hono/src/index.ts:
api/hono/src/index.ts
.get(
  "/health",
  describeRoute({
    tags: ["System"],
    description: "Get the system health",
    responses: {
      200: {
        description: "OK",
        content: {
          "application/json": {
            schema: resolver(
              z.object({
                data: z.object({
                  environment: z
                    .enum(["local", "development", "test", "staging", "production"])
                    .meta({ example: env.NODE_ENV }),
                  message: z.string().meta({ example: "ok" }),
                  version: z.string().meta({ example: BUILD_VERSION }),
                }),
              }),
            ),
          },
        },
      },
    },
  }),
  (c) => {
    const data = { message: "ok", version: BUILD_VERSION, environment: env.NODE_ENV }
    return c.json({ data })
  },
)

Use Cases

Health Monitoring

Use this endpoint for uptime monitoring services like UptimeRobot or Pingdom

Load Balancer Checks

Configure load balancers to verify instance health before routing traffic

Deployment Verification

Verify successful deployments by checking the version number

Environment Validation

Confirm the correct environment is running in each deployment

Monitoring Example

You can use the health endpoint in a monitoring script:
async function checkHealth() {
  try {
    const response = await fetch('https://your-domain.com/api/health')
    
    if (!response.ok) {
      throw new Error(`Health check failed with status: ${response.status}`)
    }
    
    const { data } = await response.json()
    
    console.log('Service is healthy')
    console.log(`Version: ${data.version}`)
    console.log(`Environment: ${data.environment}`)
    
    return true
  } catch (error) {
    console.error('Health check failed:', error)
    return false
  }
}

// Run health check every 30 seconds
setInterval(checkHealth, 30000)

Docker Health Check

You can use this endpoint in your Docker health check:
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:3001/api/health || exit 1

Kubernetes Liveness Probe

Configure Kubernetes to use this endpoint for liveness probes:
livenessProbe:
  httpGet:
    path: /api/health
    port: 3001
  initialDelaySeconds: 5
  periodSeconds: 10
  timeoutSeconds: 3
  failureThreshold: 3

Root Endpoint

GET / - Returns version and environment without the /api prefix

OpenAPI Docs

GET /api/docs - Interactive API documentation

Next Steps

API Overview

Learn about the full API structure

Authentication

Explore authentication endpoints

Build docs developers (and LLMs) love