Skip to Content
API 参考API 接口健康检查

GET /api/v1/health

检查服务运行状态。

接口说明

  • 无需认证 - 此接口可以直接调用,无需签名
  • 用途 - 用于监控服务可用性、健康状态检查
  • 返回内容 - 服务基本信息和运行时间

请求参数

无需任何参数。

请求示例

curl -X GET "https://api.procure-core.com/api/v1/health"

响应参数

参数类型说明
codenumber状态码,0 表示成功
messagestring响应消息
data.statusstring服务状态:healthy
data.timestampstring当前时间戳(ISO 8601 格式)
data.servicestring服务名称
data.uptimenumber服务运行时长(秒)

响应示例

{ "code": 0, "message": "服务正常运行", "data": { "status": "healthy", "timestamp": "2026-02-25T10:30:00.000Z", "service": "procure-api", "uptime": 3600 } }

使用场景

1. 健康检查监控

# 每 30 秒检查一次服务状态 while true; do curl -X GET "https://api.procure-core.com/api/v1/health" sleep 30 done

2. 容器编排健康探针

Kubernetes 配置示例:

apiVersion: v1 kind: Pod metadata: name: procure-api spec: containers: - name: api image: procure-api:latest livenessProbe: httpGet: path: /api/v1/health port: 3000 initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: httpGet: path: /api/v1/health port: 3000 initialDelaySeconds: 5 periodSeconds: 5

Docker Compose 配置示例:

services: api: image: procure-api:latest healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/api/v1/health"] interval: 30s timeout: 3s retries: 3 start_period: 40s

3. 负载均衡器健康检查

配置 Nginx、HAProxy 或云服务商的负载均衡器使用此端点进行后端服务健康检查。

Nginx 配置示例:

upstream procure_backend { server api1.procure-core.com:3000; server api2.procure-core.com:3000; # 健康检查配置 check interval=3000 rise=2 fall=3 timeout=1000 type=http; check_http_send "GET /api/v1/health HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx; }

错误场景

虽然此接口通常不会返回错误,但在服务异常时可能返回:

服务不可用

状态码: 503 Service Unavailable

{ "code": 50001, "message": "服务暂时不可用", "data": { "status": "unhealthy", "timestamp": "2026-02-25T10:30:00.000Z" } }

数据库连接失败

状态码: 503 Service Unavailable

{ "code": 50002, "message": "数据库连接失败", "data": { "status": "degraded", "timestamp": "2026-02-25T10:30:00.000Z", "details": "Database connection timeout" } }

注意事项

  1. 高频调用 - 此接口无速率限制,可以高频调用
  2. 轻量级 - 接口响应非常快,适合作为健康探针
  3. 无副作用 - 多次调用不会产生任何副作用
  4. 无需缓存 - 应该实时调用以获取最新状态

相关文档