Example: Vanilla JS frontend co-working with Yii3 backend (fetch + JSON API) #479
Unanswered
Ai-TOS-789
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Example: Vanilla JS frontend co-working with Yii3 backend (fetch + JSON API)
Hi team, I built a small, working example showing Vanilla JS (no framework) co-working with a Yii3 backend and would like your input on whether this is the recommended pattern before I rely on it.
What it does
GET /api/healthreturns JSON{status, framework, frontend, time}viaResponseFactoryInterface.assets/main/app.js(IIFE + DOMContentLoaded + fetch) calls the API and updates the DOM; a button re-fetches.MainAsset(public array $js = ['app.js'];) and Yii3 publishes it topublic/assets/main/<hash>/app.js; the layout emits<script src="/assets/main/<hash>/app.js">automatically.assets/main/site.css, same bundle.Verified working
GET /api/health→ 200 JSON#yii3-vanilla-box/assets/main/<hash>/app.js(200)phpstan analyse src config --level=5→ no errorsQuestions for maintainer guidance
ResponseFactoryInterface(fromconfig/web/di/psr17.php) the blessed way to return JSON from an action? Any pitfall vs a small response helper?AssetBundle::$jsthe recommended approach, or is there a lighter/preferred mechanism?Files (verified)
assets/main/app.jssrc/Web/Api/HealthAction.phpconfig/common/routes.php(added/api/health)src/Web/Shared/Layout/Main/MainAsset.php(added$js)src/Web/HomePage/template.php(added demo box)assets/main/site.css(added styles)All reactions