🚀 博客系统API文档

服务状态: 开发中

基础URL: http://localhost:3000

生产URL: https://postapi.kgzivf.com

认证方式: API Key (Header: X-API-Key)

📋 核心接口

GET /health

健康检查接口,用于检测服务状态

GET /api/posts

获取博客文章列表,支持分页、搜索、筛选

查询参数: page, limit, category, tags, status, search

GET /api/posts/:id

根据ID获取单篇博客文章详情

GET /api/posts/slug/:slug

根据slug获取单篇博客文章详情

POST /api/posts 🔒 需要认证

创建新的博客文章

PUT /api/posts/:id 🔒 需要认证

更新指定ID的博客文章

DELETE /api/posts/:id 🔒 需要认证

删除指定ID的博客文章

DELETE /api/posts 🔒 需要认证

批量删除博客文章

POST /api/import/markdown 🔒 需要认证

批量导入Markdown文档,支持最多50个文件

🔧 使用示例

获取文章列表

curl -X GET "http://localhost:3000/api/posts?page=1&limit=10&status=Published"

创建文章 (需要API Key)

curl -X POST "http://localhost:3000/api/posts" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: blog-api-secret-key-2024" \
  -d '{
    "title": "测试文章",
    "slug": "test-article",
    "content": "# 测试内容\n\n这是一篇测试文章。",
    "summary": "测试文章摘要",
    "category": "测试分类",
    "tags": ["测试", "API"],
    "status": "Published"
  }'

📝 数据格式

文章对象结构

{
  "id": 1,
  "title": "文章标题",
  "slug": "article-slug",
  "content": "# 文章内容\n\n正文...",
  "summary": "文章摘要",
  "category": "分类名称",
  "tags": ["标签1", "标签2"],
  "status": "Published",
  "type": "Post",
  "created_at": "2023-12-07T10:00:00.000Z",
  "updated_at": "2023-12-07T10:00:00.000Z"
}

🚨 错误处理

400 Bad Request: 请求参数错误

401 Unauthorized: 未授权访问(API Key无效)

404 Not Found: 资源不存在

429 Too Many Requests: 请求过于频繁

500 Internal Server Error: 服务器内部错误

📚 更多信息

详细的API使用说明请参考项目文档。如有问题,请联系开发团队。

项目地址: https://postapi.kgzivf.com

数据库: PostgreSQL

技术栈: Node.js + Express + PostgreSQL