📜 宋词API接口文档

本API提供300首经典宋词的查询服务,支持随机获取、条件筛选等功能。

基础URL: http://localhost:3000/api

📋 接口列表

GET /songci/random
随机获取一首宋词
{
  "code": 200,
  "message": "success",
  "data": {
    "id": 1,
    "cipai": "水调歌头",
    "author": "苏轼",
    "dynasty": "北宋",
    "title": "水调歌头·明月几时有",
    "content": ["明月几时有?把酒问青天。", ...],
    "formatted": "<div class='songci-card'>..."
  }
}
GET /songci/:id
根据ID获取指定宋词
// 示例:获取ID为1的宋词
GET /api/songci/1
GET /songci/list
按条件查询宋词列表(支持分页)
参数 类型 说明
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
GET /songci/cipai-list
获取所有词牌名列表
GET /songci/author-list
获取所有作者列表
GET /songci/stats
获取统计信息
{
  "code": 200,
  "message": "success",
  "data": {
    "total": 200,
    "cipaiCount": 50,
    "authorCount": 30,
    "dynastyStats": {
      "北宋": 80,
      "南宋": 70,
      ...
    }
  }
}

💻 使用示例

JavaScript Fetch

// 获取随机宋词
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

# 获取随机宋词
curl http://localhost:3000/api/songci/random

# 查询李清照的词
curl "http://localhost:3000/api/songci/list?author=李清照"

🎨 前端嵌入

可以直接访问主页查看古风卡片展示效果:

http://localhost:3000
提示: 所有接口均支持CORS跨域访问,可直接在浏览器或其他域名下调用。

📝 数据结构说明

字段 类型 说明
id number 宋词唯一标识
cipai string 词牌名
author string 作者
dynasty string 朝代
title string 完整标题
content array 诗词内容(数组形式,每行一个元素)
formatted string HTML格式的卡片(可选)