# 健康知识 API:查看单条知识详情与长文渲染
- **接口/接入点**:健康知识 · 查看单条知识详情 `90-88`(免费)
- **请求方式**:POST / GET | **返回格式**:JSON | **鉴权**:URL 携带 `appKey`
- **适用人群**:全栈开发者 | **阅读时间**:约 8 分钟
## 核心要点
- 查看单条详情接口只需一个必填参数 `id`(知识文章 id,来自搜索/分类结果)。
- 返回 `item` 对象,含 `content`(长文)、`title`/`stitle`/`keywords`/`intro`、`tname`(分类名称)、`ctime`(发布时间)等。
- `img` 字段文档标注"图片(无)",实际通常为空,前端必须做无图兜底。
## Why:搜索之后需要详情页
搜索/分类给出的是列表摘要(`title`、`intro`、`ctime`),用户点击后需要看到完整正文。查看单条详情接口就是为这个"详情页"场景服务的:用知识 `id` 换取完整的 `content` 长文与元数据。本文聚焦长文渲染与几个易踩的坑。
## What:接口速览
| 项目 | 说明 |
|------|------|
| 接口地址 | `https://route.showapi.com/90-88?appKey={your_appKey}` |
| 请求参数(form) | `id`(string 知识id,**必填**) |
| 返回 | `showapi_res_body.item`:`id`/`content`/`title`/`keywords`/`stitle`/`img`/`tname`/`media_name`/`tid`/`ctime`/`intro` |
| 超时 | 官方读写超时 15 秒 |
## How:按 id 取详情并渲染
**Python(requests)**
```python
import requests
APP_KEY = "YOUR_APPKEY"
URL = "https://route.showapi.com/90-88"
# id 来自搜索/分类结果中的知识文章 id
KNOWLEDGE_ID = "100001"
try:
resp = requests.post(URL, params={"appKey": APP_KEY}, data={"id": KNOWLEDGE_ID}, timeout=15)
resp.raise_for_status()
data = resp.json()
except requests.RequestException as e:
print("请求失败:", e)
raise
body = data["showapi_res_body"]
if body.get("ret_code") != "0":
print("业务错误:", body.get("ret_code"), body.get("remark"))
else:
item = body["item"]
print("标题:", item["title"])
print("副标题:", item.get("stitle"))
print("分类:", item.get("tname"))
print("发布时间:", item.get("ctime"))
print("正文长度:", len(item.get("content", "")))
print("图片:", item.get("img") or "(无图)")
```
**cURL**
```bash
curl -X POST "https://route.showapi.com/90-88?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "id=100001"
```
**Node.js(fetch)**
```javascript
const APP_KEY = "YOUR_APPKEY";
const KNOWLEDGE_ID = "100001";
const url = `https://route.showapi.com/90-88?appKey=${APP_KEY}`;
const body = new URLSearchParams({ id: KNOWLEDGE_ID });
const data = await (await fetch(url, {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body,
})).json();
const item = data.showapi_res_body.item;
console.log(item.title, "|", item.tname, "|", item.ctime);
```
### 前端渲染要点
- `content` 是长文正文,通常为 HTML 或纯文本;若是 HTML,注意做安全过滤(白名单标签)再渲染,避免 XSS。
- `title` 与 `stitle`(副标题)可分别作为大标题与副标题展示。
- `intro` 可作为摘要,在列表页已出现,详情页可用作导语。
## 返回示例与解析
```json
{
"showapi_res_code": 0,
"showapi_res_error": "",
"showapi_res_id": "f1e2d3c4b5a69788796a5b4c3d2e1f0",
"showapi_res_body": {
"ret_code": "0",
"remark": "",
"item": {
"id": "100001",
"title": "感冒了怎么办",
"stitle": "居家应对小指南",
"keywords": "感冒,发烧",
"content": "<p>感冒常见症状包括鼻塞、流涕……</p>",
"img": "",
"tname": "疾病科普",
"media_name": "健康编辑部",
"tid": "101",
"ctime": "2024-01-15 10:00:00",
"intro": "感冒常见症状与居家应对建议。"
}
}
}
```
> 字段值为结构示意,实际内容以接口返回为准;`img` 为空即文档所述"图片(无)"。
## 进阶 / 边界
- **无图兜底**:`img` 字段文档标注"图片(无)",实际常返回空字符串。前端不要写死 `<img src={item.img}>`,应先判断非空,空时显示占位图或纯文字卡片。
- **`ctime` 格式**:文档未规定统一时间格式,以接口实际返回字符串为准;如需格式化展示,建议先原样显示或做容错解析。
- **`id` 必填**:该接入点在 schema 中明确 `required: [id]`;缺 `id` 会返回业务错误,调用前务必校验。
## FAQ
**Q:id 从哪里来?**
A:来自分类列表或搜索结果中的知识文章 id(分类列表 `list[].id` 为 number,搜索 `contentlist[].id` 为 string,取用时注意类型)。
**Q:img 为什么是空的?**
A:文档明确标注该字段为"图片(无)",即接口本身不提供图片,前端应做无图兜底。
**Q:content 是 HTML 还是纯文本?**
A:以接口实际返回为准;若是 HTML,渲染前请做 XSS 过滤,只保留安全标签。
**Q:调用详情接口很慢怎么办?**
A:官方读写超时 15 秒,客户端建议超时为 15~20 秒;可对已读详情做短时缓存,减少重复拉取(见[免费额度策略](https://www.showapi.com/guides/health-knowledge-free-quota-90))。
## 相关能力与下一步阅读
- [健康知识 API:搜索知识接入实战(关键词 / 分类 / 分页)](https://www.showapi.com/guides/health-knowledge-search-90)
- [健康知识 API 内容渲染避坑:无图、时间格式、简介与标题](https://www.showapi.com/guides/health-knowledge-render-90)
- [健康知识 API 返回字段全解:分类列表 / 搜索结果 / 知识详情三大结构](https://www.showapi.com/guides/health-knowledge-fields-90)
- **本系列共 12 篇**:查看[健康知识 API 使用指南总目录](https://www.showapi.com/guides/health-knowledge-guides-90)