/grav-skills:grav-api-integrationfrom grav-skills
Adds REST API endpoints to a Grav 2.0 plugin using the Grav API plugin. Covers controller setup extending AbstractApiController, route registration via onApiRegisterRoutes, permission checks, response helpers, exceptions, and curl-based testing.
Ships in grav-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Add REST API endpoints to a Grav plugin using the Grav API plugin's extensibility system.
You are adding API integration to a Grav CMS plugin. Follow this exact pattern, which has been tested and proven with the Email and License Manager plugins.
Read the plugin's main PHP file and classes directory to understand:
Create a new file classes/{PluginName}ApiController.php that:
Grav\Plugin\Email\)Grav\Plugin\Api\Controllers\AbstractApiControllerServerRequestInterface $request and returns ResponseInterfaceKey patterns:
$this->requirePermission($request, 'api.system.read') for read endpoints$this->requirePermission($request, 'api.system.write') for write endpoints$this->getRequestBody($request) to parse JSON body$this->requireFields($body, ['field1', 'field2']) to validate required fields$this->getRouteParam($request, 'name') for URL parameters$this->getPagination($request) for paginated listings$this->fireEvent('onPluginAction', [...]) to fire eventsApiResponse::create($data) for 200 responsesApiResponse::created($data, $location) for 201 responsesApiResponse::noContent() for 204 responsesApiResponse::paginated(...) for paginated listsNotFoundException, ValidationException, ForbiddenException, ApiException for errorsAdd to the plugin's getSubscribedEvents():
'onApiRegisterRoutes' => ['onApiRegisterRoutes', 0],
Add the handler method:
public function onApiRegisterRoutes(Event $event): void
{
$routes = $event['routes'];
$controller = \Grav\Plugin\PluginName\PluginApiController::class;
$routes->get('/resource', [$controller, 'index']);
// ... more routes
}
If the plugin doesn't already have an autoload() method, add one:
public function autoload(): \Composer\Autoload\ClassLoader
{
return require __DIR__ . '/vendor/autoload.php';
}
Then run composer dump-autoload in the plugin directory.
Create an api-docs/ directory with:
chapter.md — Overview page with Helios chapter templateapi-endpoint.md with the Helios api-endpoint template frontmatter:
api:
method: POST
path: /resource
description: 'What it does'
parameters: [{name, type, required, description}]
request_example: '{"json": "example"}'
response_example: '{"data": {...}}'
response_codes: [{code, description}]
grav-{plugin}-api.postman_collection.json using Postman v2.1 format with explicit headers (X-API-Key: {{api_key}}, X-Grav-Environment: {{grav_environment}}, Content-Type: application/json) and standard variables ({{base_url}}, {{api_prefix}})Add an "## REST API Integration" section to the plugin's README.md documenting:
Clear the route cache (cache/api/route.cache) and test every endpoint with curl:
curl -sk "https://localhost/grav-api/api/v1/your-endpoint" \
-H "X-API-Key: YOUR_KEY" \
-H "X-Grav-Environment: localhost"
$user->authorize() does NOT work outside admin context — use $user->get('access.permission.name') via the isSuperAdmin() and hasPermission() helpers on AbstractApiControllerUserCollection iteration doesn't work in API context — scan account files directly if neededWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
9 skills in this plugin
/grav-2-migrationUse when migrating an existing Grav 1.7/1.8 site to Grav 2.0 by hand — the agent-driven equivalent of what the `migrate-grav` plugin's wizard does, for sites where core is swapped in place (git checkout, deploy pipeline, rsync) rather than staged in a subdirectory and promoted. Covers the whole sequence: preflight and a restore point, swapping core, bringing plugins/themes to their 2.0 releases and replacing classic `admin` with `admin2` + `api`, translating classic `admin.*` account and group permissions into the `api.*` set 2.0 actually enforces (including the `api.access` gate no 1.x permission corresponds to), reopening the `security.twig_content` gates and seeding `security.twig_sandbox` allowlists from the site's own content, `system.images.url_actions`, the GFM `tagfilter`, and verifying the result. Trigger when the user says "migrate this site to Grav 2", "upgrade my 1.7 site to 2.0", asks to do what migrate-grav does without running the plugin, or asks why Twig in content, image resizing, raw HTML, or a user's permissions broke after moving to Grav 2.0./grav-admin-ui-polishUse when reviewing, auditing or polishing the admin UI of a Grav 2.0 plugin that renders inside Admin Next (admin2) — a plugin page in component mode, an add-on section, a dashboard widget, a custom field, or a blueprint settings form. Covers the review method (walk both themes plus a tablet width via the same-origin iframe trick, read-only, demo rows injected client-side when the seed is empty, then one code-side consistency pass against the host's own tokens), the ten design rules that repeat across every view (status registry instead of raw enums, the zero-value rule, one primary per screen with destructive neutral at rest, one entry point per row with a ⋯ menu, collapsed creation forms, effective state instead of stored flags, one date and number format, counts for the whole result set, prose into `<details>`, every "see X" a link, every editor a route with a dirty guard, sub-nav groups, empty states with a CTA), host fit against Admin Next's `--background/--muted/--border/--input/--ring/--success/--warning/--destructive` custom properties and its badge/button/card/table/tabs/segmented/input conventions, the `--kc-*`-style token block and constructable-stylesheet pattern, the primitives a plugin admin needs (`status()`, `rowActions()`, `emptyState()`, `.table-scroll`, route + dirty-guard helpers, formatting helpers), the `ctx.ui` / `ctx.sheet` / `ctx.route` / `ctx.navigate` / `ctx.setTitle` contract an add-on section is handed, blueprint label and help-text rules, a twelve-item rendering-defect checklist, and the host/API limitations to plan around. Trigger when the user says "review the admin UI", "polish this plugin page", "make it feel native", "make it look premium", "bring it in line with KahunaCart", or mentions Admin Next, admin2, plugin page, kc-view, web component admin UI, blueprint labels/help, status pills, dark mode contrast, rendering defects, or a UI review of a Kahuna add-on (subscriptions, licenses, payment providers)./grav-api-admin-next-integrationUse when integrating a Grav 2.0 plugin with Admin Next (the new SvelteKit SPA admin) and the API plugin. Covers all integration points: API endpoints (`onApiRegisterRoutes`), sidebar items, menubar/toolbar buttons, floating widgets, modal dialogs (`window.__GRAV_DIALOGS.form()`/`.open()` and the page-creation deep link), plugin pages (blueprint and component modes), custom field types, custom reports, blueprint modifications, permissions, languages, and config exposure to web components. Trigger when migrating an admin-classic plugin to Admin Next, when adding any Admin Next UI to a plugin, when working under `user/plugins/<plugin>/admin-next/` or on event handlers prefixed `onApi*`, or when the user mentions admin-next, custom field type, sidebar nav, floating widget, modal dialog, plugin page, custom report, or any of the `onApi*` events. Use the lighter `grav-api-integration` skill instead if the plugin only needs API endpoints with no admin UI./grav-inbox-triageUse for Andy's daily sweep of his GitHub notifications on the Grav org (getgrav/*): issues, pull requests, discussions and mentions. Trigger on "do my inbox", "triage my notifications", "daily inbox", "clear my github inbox", or a request to work through getgrav issues and PRs. Runs end to end without check-ins: reproduces each bug on a local reeve install, fixes it on the repo that actually owns the code (often not where it was filed), verifies the fix, merges contributor PRs with corrections applied on top, commits and pushes to develop with a CHANGELOG bullet, posts a short reply, closes the issue, and marks the notification done. Only items that need a decision from Andy (product or design calls, behavior or interface changes, releases, anything that couldn't be verified) stop and wait. Security advisories are left for the weekly grav-security-advisories run./grav-plugin-reviewUse when reviewing a third-party Grav 2.0 / Admin2 plugin for compatibility and security, especially a GPM (`getgrav/grav` `[add-resource]`) submission. Covers the review method (clone, map, cross-check against the real api/admin2/login plugins in the workspace), the verified API/Admin2 integration contract (which `onApi*` events exist, `AbstractApiController` shape, public-route mechanism, component-page convention, settings-panel secret-leak vector), and a findings taxonomy with concrete fixes: manifest/GPM correctness, auth granularity, secret handling, unauthenticated public writes, CSV/mail-header injection, XSS escaping, path traversal in file-serving, SVG upload, open proxies, pure-PHP SSE worker exhaustion, CSRF, message/identity spoofing, account mass-assignment, plus citizen-behavior and author-branding-in-defaults smells. Also covers how to produce a paste-ready, file:line-referenced handoff. Trigger when the user asks to review/vet/audit a Grav plugin, asks about a GPM submission, links a `grav-plugin-*` repo for review, or mentions checking a plugin for Grav 2.0 / Admin2 compatibility./grav-releaseUse when cutting a release of a Grav plugin (Team Grav / Trilby Media, e.g. `grav-plugin-*`) or Grav core itself. Covers the two release shapes — full git-flow when the work is on `develop`, and tag-only when the work is on a dedicated release branch (like flex-objects `1.4.0` or an older Grav maintenance line like `1.7`) — plus the prerelease decision (`testing: true` in blueprints, or an `-rc.`/`-beta.` version, or Grav core's `system/defines.php`), the bare-numeric tag/title rule (never `v`-prefixed), sourcing release notes from the top CHANGELOG block, and post-release verification. Trigger when the user says "release <plugin>", "cut a release", "tag and release", "get <plugin> out", "do a prerelease", or asks to run a git-flow release / `gh release` for a Grav plugin or Grav core.npx claudepluginhub getgrav/grav-skills --plugin grav-skills