Abilities API 开发文档

REST API

Estimated reading: 2 minutes 3 views 贡献人员

概述

Abilities API 提供了一组 REST 接口,用于:

  • 发现站点中已注册的能力
  • 通过 HTTP 请求执行能力
  • 供 AI Agent / 外部系统 / 自动化工具调用

REST API 命名空间:

/wp-abilities/v1

一、REST 暴露控制(非常关键)

默认情况下:

能力不会自动暴露到 REST API

必须在注册能力时显式设置:

'meta' => [
  'show_in_rest' => true
]

否则访问 REST 接口将返回:

{
  "code": "rest_ability_not_found"
}

二、列出能力列表

GET /wp-abilities/v1/abilities

支持参数:

  • page
  • per_page
  • category

三、执行能力(Run Endpoint)

GET|POST|DELETE /wp-abilities/v1/{namespace}/{ability}/run

HTTP Method 规则(强制)

能力类型Method
readonlyGET
普通写操作POST
destructiveDELETE

这是 Abilities API 区别于普通 REST API 的核心设计之一


四、输入方式说明

  • GET / DELETE:input 作为 URL 编码 JSON
  • POST:input 作为 JSON body

五、认证方式

支持所有 WordPress REST 认证方式:

  • Cookie(同源)
  • Application Password(推荐)
  • 自定义认证插件

留下第一个评论