跳转到内容

主题颜色

颜色来源
种子颜色
色板风格

接口总览

所有接口都挂在 /api 下,请求与响应都是 JSON。

除健康检查外,所有请求都要带一个 API Key:

Authorization: Bearer <API_KEY>

Key 在 cms.config.ts 旁边的 .env 里配置,不要提交进仓库。缺 Key 返回 401,Key 无权限返回 403。

方法 路径 说明
GET /api/collections/:name 按集合列出内容
GET /api/collections/:name/:id 取单条内容
POST /api/collections/:name 新建内容
PATCH /api/collections/:name/:id 局部更新
DELETE /api/collections/:name/:id 删除内容

列表接口用 limit(默认 20,最大 100)和 cursor 两个参数:

GET /api/collections/post?limit=20&cursor=eyJpZCI6MTJ9

响应里带下一页游标,最后一页的 nextCursor 为 null:

{
"items": [{ "id": 12, "title": "第一篇" }],
"nextCursor": null
}
状态码 含义
400 请求体不符合模型定义,details 里指出是哪个字段
401 缺少或无效的 API Key
403 Key 有效但没有该集合的权限
404 集合或内容不存在
409 唯一字段冲突,例如重复的 slug

不同产品之间共用同一套错误结构:{ error: { code, message, details? } }。