webapi
Skill6 starsChanged 28 days agoMITView on GitHub
Contract-first generator for Magento 2 REST / Web-API surfaces. Use to expose an existing entity over REST: add an endpoint, service contract, repository, or custom action. Generates webapi.xml, Api/ + Api/Data interfaces, a repository, di.xml, acl.xml, and API tests. Goes beyond magento2-tools:module-create's webapi stubs with SearchCriteria, per-route auth scopes, and extension attributes. Assumes the entity model already exists (from magento2-tools:module-create).
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 35
Append, don't replace: When etc/webapi.xml, di.xml, or acl.xml already exist (e.g.
- Very specific: line 55
If the entity model is absent, stop: instruct the user to run module-create first.
- Very specific: line 99
Apply the shared module-hygiene baseline (required): After generating or modifying PHP files, run …
- Very specific: line 105
Run review --diff on the module.
- Distinctive: line 114
Test coverage delta and the run command.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Magento 2 Web API Create
Contract-first REST / Web-API generation for an existing entity. Produces:
etc/webapi.xmlwith CRUD routes (+ optional custom-action routes), each with an auth scopeApi/{Entity}RepositoryInterfaceservice contract (CRUD + any custom-action methods)Api/Data/{Entity}Interface+Api/Data/{Entity}SearchResultsInterfaceDTOsModel/{Entity}Repositoryfull implementation (SearchCriteriaviaCollectionProcessor)etc/di.xmlpreferences andetc/acl.xmlresources- A Web-API functional test (
WebapiAbstract) covering the GET/POST/PUT/DELETE round-trip
Core Rules
- Contract-first. Decide the endpoint surface, DTO shape, and auth scope before writing the
implementation. The
Api/interface is the contract; everything else implements it. - Assumes the entity exists. This skill operates on the model / resource-model /
db_schemaproduced bymodule-create. If the entity model is absent, stop and runmodule-createfirst — do not scaffold persistence here. - Auth on every route. Each route declares a
<resources>scope. ACL-protected is the default;selffor customer-scoped data;anonymousrequires explicit justification (it exposes the route publicly). - Throw framework exceptions. Map failures to the right framework exception so the Web API
returns the correct HTTP status (
NoSuchEntityException→ 404,CouldNotSaveException→ 400,LocalizedException→ 400). Seereferences/error-handling.md. - Append, don't replace. When
etc/webapi.xml,di.xml, oracl.xmlalready exist (e.g. module-create stubs), append/extend rather than overwrite. Report what is reused. - Literal
entity_idPK. The module-create entity uses the literalentity_idprimary key; this skill matches it (not the token{entity}_idused by the adminhtml form/listing pairing). - Coding style. Generated PHP follows PER-CS 3.0 as the baseline, with the Magento 2 coding
standard taking precedence on any conflict;
--standard=Magento2PHPCS is the gate. Seecontext/references/php-coding-style.md. - Source of truth. Generate from templates → shared references → baked-in Magento 2 knowledge
→ official Magento/Adobe docs (live-fetched only when uncertain). Do NOT read, grep, or "study"
other modules under
app/code/vendor/*/Magento core to infer conventions, entity shapes, naming, or wiring. Narrow exceptions: the target module/class of this operation, and the specific contract of a module this code explicitly depends on. Affirm sources in the final report. Seecontext/references/source-of-truth.md.
Workflow
Phase 0 — Context Resolution
Invoke context (vendor, runner, Magento root, version). Then detect the target entity:
- Locate
Model/{Entity},Model/ResourceModel/{Entity}, and any existingApi/Data/{Entity}Interface. - If the entity model is absent, stop: instruct the user to run
module-createfirst. - Detect existing
etc/webapi.xml,etc/di.xml,etc/acl.xml,etc/extension_attributes.xml, and any partialApi/surface — these are reused/extended, not overwritten.
Phase 1 — Contract Plan
Ask the user:
- Entity: the existing model being exposed.
- CRUD surface: confirm the five baseline routes (always generated):
GET :id→getById,GET→getList,POST→save,PUT :id→save,DELETE :id→deleteById. - Custom actions (optional): for each — name, HTTP method, URL, service method, auth scope.
e.g.
POST /V1/{route}/:entityId/activate → activate(int $entityId): {Entity}Interface. - Auth scope per route:
anonymous|self| ACL-protected (default). Seereferences/auth-scopes.md.
Produce the route table. See references/service-contracts.md.
Phase 2 — DTO & Repository Plan
For the DTO and repository, decide:
- Data interface fields (constants + typed getters/setters) and extension-attribute accessors.
See
references/extension-attributes.md. - Search-results interface — narrowed
getItems()returning{Entity}Interface[]. - Repository wiring — resource model, collection factory,
CollectionProcessorInterface,SearchResultsFactory, entity factory. Seereferences/search-criteria.md. - Custom-action bodies — delegate non-trivial logic to a domain service; never bury business logic in the repository.
Present the plan. Wait for approval.
Phase 3 — Generate
Api/{Entity}RepositoryInterface.php(CRUD + custom-action signatures).Api/Data/{Entity}Interface.php,Api/Data/{Entity}SearchResultsInterface.php.Model/{Entity}Repository.php(full implementation).etc/webapi.xml(routes + per-route<resources>), appended if the file exists.etc/di.xml— three preferences:{Entity}Interface→ model,{Entity}RepositoryInterface→ repository,{Entity}SearchResultsInterface→Magento\Framework\Api\SearchResults.etc/acl.xml— the resource tree the routes reference.Test/Api/{Entity}RepositoryTest.php(WebapiAbstractfunctional test).
Phase 4 — Verify
php -lon each generated.php;xmllint --noouton each generated XML.- Apply the shared module-hygiene baseline (required). After generating or modifying PHP files, run
${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/add-license-headers.sh {ctx.magento_root}/app/code/{Vendor}/{Module} {Vendor}to stamp the standard copyright header onto every new.php(idempotent — it skips files that already carry it). When adding acomposer.jsonrequireentry, resolve a bounded constraint via${CLAUDE_PLUGIN_ROOT}/skills/context/scripts/resolve-dep-constraint.sh <vendor/package>— never"*". Seecontext/references/module-hygiene.md. - Run
review --diffon the module. Gate: zero Critical/High. - Where a running Magento is available, suggest
setup:di:compileas a smoke check (not required).
Phase 5 — Report
Brief Markdown:
- Endpoints added (method, URL, service method, auth scope).
- Custom actions added.
- DTO fields + extension-attribute decisions.
- Test coverage delta and the run command.
reviewverdict.
Docs may now be stale. This change modified module code. Run
docs --module={Vendor}_{Module}to refresh the module's README, CHANGELOG, anddocs/*.md(technical reference, guides, and API references as applicable).
Inputs
/webapi [--module=<Vendor>_<Module>] [--entity=<Entity>] [--auth=anonymous|self|acl]Interactive flow drives the rest.
Outputs
{ctx.magento_root}/app/code/{Vendor}/{Module}/etc/webapi.xml # created or appended
{ctx.magento_root}/app/code/{Vendor}/{Module}/etc/di.xml # created or merged
{ctx.magento_root}/app/code/{Vendor}/{Module}/etc/acl.xml # created or merged
{ctx.magento_root}/app/code/{Vendor}/{Module}/Api/{Entity}RepositoryInterface.php # new
{ctx.magento_root}/app/code/{Vendor}/{Module}/Api/Data/{Entity}Interface.php # new
{ctx.magento_root}/app/code/{Vendor}/{Module}/Api/Data/{Entity}SearchResultsInterface.php # new
{ctx.magento_root}/app/code/{Vendor}/{Module}/Model/{Entity}Repository.php # new
{ctx.magento_root}/app/code/{Vendor}/{Module}/Test/Api/{Entity}RepositoryTest.php # newReference Files
references/service-contracts.md— repository pattern,@api, why interfaces live inApi/.references/search-criteria.md—CollectionProcessor, filter/sort/pagination,SearchResultsFactory.references/auth-scopes.md— anonymous / self / ACL scopes, integration tokens, when anonymous is OK.references/error-handling.md— exception → HTTP-status mapping; throw the right framework exception.references/extension-attributes.md—extension_attributes.xmland the generated extension interface.references/webapi-testing.md—WebapiAbstract, REST vs SOAP adapters, asserting status codes.context/references/source-of-truth.md— source-of-truth hierarchy + the no-unrelated-module-scanning rule (allowed reads, live-doc fetch protocol, report affirmation).
Templates
templates/service-contract-interface.phptemplates/data-interface.phptemplates/search-results-interface.phptemplates/repository.phptemplates/webapi.xmltemplates/di.xmltemplates/acl.xmltemplates/test-webapi-functional.php
Acceptance Criteria
webapi.xmlroutes resolve to real service-contract methods; each route has a<resources>scope.- The service contract is an
@apiinterface underApi/; the DTO underApi/Data/. getListprocessesSearchCriteriathroughCollectionProcessorInterface(filters/sort/pagination).- Failures throw the framework exception that maps to the correct HTTP status.
- Anonymous routes carry an explicit justification.
- The generated repository has at least one functional test (GET/POST/PUT/DELETE round-trip).
Related Skills
| Phase | Skill |
| 0 | context |
| (prerequisite) | module-create (entity + persistence) |
| (after Phase 3) | review --diff |
| (after Phase 3) | test-generate --types=api |
| (caller) | feature Phase 5 (A* / API tasks) |
| (sibling) | graphql (GraphQL surface for the same entity) |
In this repository35 other files it gives its agents.
- a11y-auditSkill
- admin-formSkill
- admin-listingSkill
- auditSkill
- breeze-adaptSkill
- breeze-compatSkill
- breeze-themeSkill
- cli-commandSkill
- contextSkill
- data-migrationSkill
- debugSkill
- deploySkill
- docsSkill
- eav-attributeSkill
- extension-pointSkill
- featureSkill
- fixSkill
- frontendSkill
- graphqlSkill
- i18nSkill
- indexerSkill
- lintSkill
- marketplaceSkill
- message-queueSkill
- module-createSkill
- perf-auditSkill
- releaseSkill
- remediateSkill
- reviewSkill
- securitySkill
- system-configSkill
- test-generateSkill
- triageSkill
- upgradeSkill
- widgetSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

