# 检查服务健康

探测当前运行实例能否访问数据库。健康时响应 200 和文本 OK。

GET `/health`

- **认证** 公开，无需登录。
- **成功状态** `200`

## 请求参数

此操作无需提交参数。

## 请求示例

**cURL**

```bash
curl -i -X GET 'https://social2api.com/health'
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, urlopen

request = Request(
    "https://social2api.com/health",
    method="GET",
)
send = urlopen
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/health", {
  method: "GET",
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```text
OK
```

**错误示例**

```json
Database unavailable
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `body` | string | 健康时为 OK。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `503` | 数据库不可用。 |

## 使用细节

-   完整 Node 后端通过数据库的轻量查询验证连通性。

## 同组接口

-   [HEAD 检查服务状态码](<https://social2api.com/docs/api/health-head/>)

规范页面：<https://social2api.com/docs/api/health-get/>
