本API提供300首经典宋词的查询服务,支持随机获取、条件筛选等功能。
http://localhost:3000/api
{
"code": 200,
"message": "success",
"data": {
"id": 1,
"cipai": "水调歌头",
"author": "苏轼",
"dynasty": "北宋",
"title": "水调歌头·明月几时有",
"content": ["明月几时有?把酒问青天。", ...],
"formatted": "<div class='songci-card'>..."
}
}
// 示例:获取ID为1的宋词
GET /api/songci/1
| 参数 | 类型 | 说明 |
|---|---|---|
| cipai | string | 词牌名(模糊搜索) |
| author | string | 作者名(模糊搜索) |
| dynasty | string | 朝代(模糊搜索) |
| keyword | string | 关键词搜索(标题或内容) |
| page | number | 页码,默认1 |
| limit | number | 每页数量,默认10 |
// 示例:查询苏轼的词,第1页,每页5首
GET /api/songci/list?author=苏轼&page=1&limit=5
{
"code": 200,
"message": "success",
"data": {
"total": 200,
"cipaiCount": 50,
"authorCount": 30,
"dynastyStats": {
"北宋": 80,
"南宋": 70,
...
}
}
}
// 获取随机宋词
fetch('http://localhost:3000/api/songci/random')
.then(response => response.json())
.then(data => {
console.log(data.data);
});
// 按作者查询
fetch('http://localhost:3000/api/songci/list?author=苏轼')
.then(response => response.json())
.then(data => {
console.log(data.data);
});
# 获取随机宋词
curl http://localhost:3000/api/songci/random
# 查询李清照的词
curl "http://localhost:3000/api/songci/list?author=李清照"
可以直接访问主页查看古风卡片展示效果:
http://localhost:3000
| 字段 | 类型 | 说明 |
|---|---|---|
| id | number | 宋词唯一标识 |
| cipai | string | 词牌名 |
| author | string | 作者 |
| dynasty | string | 朝代 |
| title | string | 完整标题 |
| content | array | 诗词内容(数组形式,每行一个元素) |
| formatted | string | HTML格式的卡片(可选) |