| sidebar_position | 3 | |||||||
|---|---|---|---|---|---|---|---|---|
| title | Headless API 指南 | |||||||
| description | ReactPress Headless REST API — Swagger 文档、API Key 认证、文章列表 curl 示例与 Toolkit TypeScript SDK。 | |||||||
| keywords |
|
ReactPress 默认提供 Headless REST API,任意前端(Next.js、Remix、移动端)均可通过 HTTP 获取与写入内容。
本地启动后访问 Swagger UI:
http://localhost:3002/api
生产环境:https://your-api-domain.com/api
Admin SPA 使用登录后的 Bearer Token,适用于浏览器内请求。
- 创建带
read,write的 Key:
reactpress content key --create --save
# 或:Admin JWT → POST /api/api-key body: { "name": "agent", "scopes": "read,write" }- 请求头携带:
curl -H "X-API-Key: YOUR_KEY" \
"http://localhost:3002/api/article/headless/list?status=publish&page=1&pageSize=10"read:GET /api/article/headless/listwrite(或*):创建/更新/删除文章、标签、分类,以及上传媒体
:::warning Write-scoped API Key 等同于管理员写权限,勿提交到公开仓库。生产环境使用 HTTPS 并定期轮换。 :::
外部 Agent(Cursor 等)可安装便携 Skill,完成「安装站点 → 写稿 → 发布」:
npx skills add reactpressjs/reactpress --skill blog-ai -a cursor -y详见仓库 skills/blog-ai/SKILL.md。
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /api/health |
健康检查 |
| GET | /api/article/headless/list |
已发布文章分页列表(API Key read) |
| GET | /api/article/:id |
单篇文章 |
| GET | /api/page/list |
页面列表 |
| GET | /api/category |
分类 |
| GET | /api/tag |
标签 |
| GET | /api/comment/list |
评论 |
| GET | /api/setting/public |
公开站点设置 |
| POST | /api/article |
创建文章(JWT admin 或 API Key write) |
| PATCH | /api/article/:id |
更新/发布文章(JWT admin 或 API Key write) |
| POST | /api/file/upload |
上传媒体(JWT admin 或 API Key write) |
精确路径与参数以 Swagger 为准。
curl http://localhost:3002/api/healthcurl -G "http://localhost:3002/api/article/headless/list" \
-H "X-API-Key: YOUR_KEY" \
--data-urlencode "status=publish" \
--data-urlencode "page=1" \
--data-urlencode "pageSize=10"推荐在 Node / React 中使用强类型客户端:
npm install @reactpressjs/reactpress-toolkitimport { api } from '@reactpressjs/reactpress-toolkit';
const articles = await api.article.findAll({
status: 'publish',
page: 1,
pageSize: 10,
});详见 Toolkit 使用指南。
Server 在内容变更时向配置的 URL 发送 HTTP POST,例如 article.published。与 Plugin Hook(入站、可改数据)互补。
配置:Admin → 设置 → Webhook
- Fork reactpress-theme-starter
- 设置环境变量指向 API:
NEXT_PUBLIC_API_URL - 部署到 Vercel / 自托管 Node
- 内容仍在 ReactPress API,前端独立发布
远程 Admin / 桌面客户端 / 第三方前端需 API 允许对应 Origin。生产部署时在 Server 或 Nginx 层配置 CORS 白名单。