Skip to content

Commit 4731ff3

Browse files
committed
Extend information about HTTP methods used when executing ability with REST API
1 parent a896a43 commit 4731ff3

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

docs/5.rest-api.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,42 @@ curl https://example.com/wp-json/wp/v2/abilities/my-plugin/get-site-info
143143

144144
## Execute an Ability
145145

146+
Abilities are executed via the `/run` endpoint. The required HTTP method depends on the ability's `readonly` annotation:
147+
148+
- **Read-only abilities** (`readonly: true`) must use **GET**
149+
- **Regular abilities** (default) must use **POST**
150+
151+
This distinction ensures read-only operations use safe HTTP methods that can be cached and don't modify server state.
152+
146153
### Definition
147154

148-
`POST /wp/v2/abilities/(?P<namespace>[a-z0-9-]+)/(?P<ability>[a-z0-9-]+)/run`
155+
`GET|POST /wp/v2/abilities/(?P<namespace>[a-z0-9-]+)/(?P<ability>[a-z0-9-]+)/run`
149156

150157
### Arguments
151158

152159
- `namespace` _(string)_: The namespace part of the ability name.
153160
- `ability` _(string)_: The ability name part.
154161
- `input` _(integer|number|boolean|string|array|object|null)_: Optional input data for the ability as defined by its input schema.
162+
- For **GET requests**: pass as `input` query parameter (URL-encoded JSON)
163+
- For **POST requests**: pass in JSON body
155164

156-
### Example Request (No Input)
165+
### Example Request (Read-only, GET)
157166

158167
```bash
159-
curl -X POST https://example.com/wp-json/wp/v2/abilities/my-plugin/get-site-info/run
168+
# No input
169+
curl https://example.com/wp-json/wp/v2/abilities/my-plugin/get-site-info/run
170+
171+
# With input (URL-encoded)
172+
curl "https://example.com/wp-json/wp/v2/abilities/my-plugin/get-user-info/run?input=%7B%22user_id%22%3A1%7D"
160173
```
161174

162-
### Example Request (With Input)
175+
### Example Request (Regular, POST)
163176

164177
```bash
178+
# No input
179+
curl -X POST https://example.com/wp-json/wp/v2/abilities/my-plugin/create-draft/run
180+
181+
# With input
165182
curl -X POST \
166183
-H "Content-Type: application/json" \
167184
-d '{"input":{"option_name":"blogname","option_value":"New Site Name"}}' \
@@ -214,5 +231,5 @@ The API returns standard WordPress REST API error responses with these common co
214231
- `ability_invalid_output` - output validation failed according to the ability's schema.
215232
- `ability_invalid_execute_callback` - the ability's execute callback is not callable.
216233
- `rest_ability_not_found` - the requested ability is not registered.
217-
- `rest_ability_invalid_method` - the requested HTTP method is not allowed for executing the selected ability.
234+
- `rest_ability_invalid_method` - the requested HTTP method is not allowed for executing the selected ability (e.g., using POST on a read-only ability or GET on a regular ability).
218235
- `rest_ability_cannot_execute` - the ability cannot be executed due to insufficient permissions.

0 commit comments

Comments
 (0)