Skill: REST APIs
Este conteúdo não está disponível em sua língua ainda.
Read the bundled conventions before applying this skill.
Decisions that affect behavior
Section titled “Decisions that affect behavior”- Preserve the API’s routes, media types, response envelope, status codes, and
authentication scheme.
rest\Controllerconfigures negotiation, verbs, CompositeAuth, and rate limiting, but an empty authentication-method list is not proof that endpoints require credentials. Rate limiting also depends on the configured identity supporting its contract. - Merge inherited behaviors deliberately. When adding CORS, handle preflight in the intended filter order and preserve authentication on actual requests. CORS permission is not authorization. REST defaults disable CSRF; if the API uses ambient cookie/session credentials, explicitly evaluate that policy instead of treating the default as a security guarantee.
- ActiveController supplies index/view/create/update/delete/options actions;
overriding an inline method does not automatically replace a mapped external
action. Inspect
actions()and alter only the intended entry. Its defaultcheckAccess()is empty: implement the application’s resource-level policy. Filter list queries for allowed resources; checking access to an index action does not by itself constrain every row returned. - Distinguish request parser configuration from response negotiation. JSON body loading depends on the configured parser/content type. Keep create/update scenarios and safe input attributes separate from serialized output fields.
- Review
fields()/extraFields()and requested expansions. Serialization is not authorization and may expose nested resources or trigger extra queries. Preserve pagination headers/envelopes and HEAD behavior while changing data. - Use the existing error contract for validation, missing resources, unsupported verbs/media, and denied access. Do not convert every exception into HTTP 200 with an error string or leak arbitrary model attributes for convenience.
Observable acceptance
Section titled “Observable acceptance”Request the affected endpoints through the real parser/filter/serializer path. Check the expected body, headers, status and field set for permitted access, validation failure, missing resource, denied access, and the changed media/verb cases. Exercise collection visibility separately from single-resource checks. For CORS changes verify preflight and actual authenticated requests. An action unit test alone does not establish the HTTP contract.
Evidence routes
Section titled “Evidence routes”Read framework/rest/{Controller,ActiveController,Action,IndexAction,Serializer,UrlRule}.php,
framework/filters/{ContentNegotiator,Cors,RateLimiter}.php, and the configured
framework/filters/auth/ strategy. Tests: tests/framework/rest/SerializerTest.php,
tests/framework/rest/IndexActionTest.php, tests/framework/rest/UrlRuleTest.php,
tests/framework/filters/ContentNegotiatorTest.php, CorsTest.php, and
tests/framework/filters/auth/CompositeAuthTest.php.
Guides: rest-controllers, rest-authentication, rest-resources,
rest-response-formatting, rest-routing.
Install and activate this skill
Section titled “Install and activate this skill”Select yii2-rest-apis in the installation and client verification guide.
Complete the one-time Composer setup. The common yii2-extensions/skill package installs all twenty framework skills; no separate installer is needed for yii2-rest-apis.
composer installcomposer skills:showWith auto-sync set to true, dependency installs and updates synchronize the trusted skills. If it is false, run composer skills:update after dependency installation or updates.
Optional npx installation
Section titled “Optional npx installation”npx skills@1.7.2 add yii2-extensions/skill --skill yii2-rest-apis --agent codexInstall the complete bundle, including referenced resources. The canonical SKILL.md is also available for direct reading.
Continue with the related framework guide.