Add Vanilla JS + Yii3 co-work example (JSON API + fetch) - #480
Conversation
- New JSON API endpoint GET /api/health via ResponseFactoryInterface - Register plain assets/main/app.js (Vanilla JS) through MainAsset - Homepage demo box fetches the API and updates the DOM - Verified: API 200 JSON, asset published, phpstan level 5 clean See #478 and /discussions/479
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #480 +/- ##
============================================
- Coverage 85.08% 78.17% -6.92%
- Complexity 29 31 +2
============================================
Files 11 12 +1
Lines 181 197 +16
============================================
Hits 154 154
- Misses 27 43 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Adds a minimal, dependency-free example of Vanilla JS working together with a Yii3 backend, demonstrating the recommended way to:
ResponseFactoryInterface)AssetBundle(auto-published topublic/assets)Changes
src/Web/Api/HealthAction.php(new):GET /api/healthJSON endpoint.config/common/routes.php: registerRoute::get('/api/health').src/Web/Shared/Layout/Main/MainAsset.php: registerapp.jsin$js.assets/main/app.js(new): Vanilla JS fetching/api/health, updating DOM, with a refresh button. Lint-clean.src/Web/HomePage/template.php: demo box (#yii3-vanilla-box).assets/main/site.css: styles for the demo box/badge/button.Verification
GET /api/healthreturns 200 JSON{status, framework, frontend, time}.<script src="/assets/main/<hash>/app.js">and<link .../site.css>are emitted automatically.phpstan analyse src config --level=5→ no errors.Note / question for reviewers
While building this I hit
WebViewRenderer::render('')throwing "The view path is not set" when trying to return a raw JSON response. This PR usesResponseFactoryInterfaceinstead. Should the template/docs recommendResponseFactoryInterfacefor JSON APIs, and/or shouldWebViewRendererallow an empty view path for API actions? (Tracked in #478 and discussions/479.)How to test