The main pillar: @crudadmin/helpers
The frontends never talk to the backend with a bare fetch or their own axios setup. They use the @crudadmin/helpers npm package. It is the single layer through which an application communicates with CrudAdmin:
- an axios wrapper adding the auth token, the language and the platform headers to every request,
Response, which shows the message of a response as a toast and binds thestoreobject of the response into Pinia stores,- one bootstrap request filling the stores when the app starts, and refreshing them,
- auth (login, logout, token storage), modals, toasts, gettext translations and localized routes.
GET /admin/api/bootstrap, binds the store object into its Pinia stores through Response and uses Modal, Toast and the translator of @crudadmin/helpers. See Admin Vue API.
How data travels
- The backend puts shared data into sections of a bootstrap request class (
AppRequest). Each section is named after the Pinia store which receives it. - A controller answers with
autoAjax(). Whatever it puts into->store([...])ends in thestorekey of the JSON. - The frontend calls the API through
useAxios()and hands every response, success or error, touseResponse(). Responsewrites each key ofstoreinto the store with the same id, and showsmessageas a toast.
Where to read next
Sharing data with the frontend
The response format, the store binding rules and the controller patterns. Start here.
Bootstrap request
The backend side:
AppRequest, its sections, guests, caching and several apps.@crudadmin/helpers
Installing the package as a Nuxt layer or in a Vite app.
App boot and auth
The bootstrap, its refresh, the auth token and the hooks of the Nuxt layer.
Requests and responses
useAxios(), useResponse(), headers and offline requests.Pinia stores
Which stores receive data, the helpers stores and extending them.
Rules shared by every project
- Every frontend request goes through
useAxios()from@crudadmin/helpers, and every response throughuseResponse(). - Data shared by the whole app comes from the bootstrap request, not from page specific endpoints.
- A section of the bootstrap and the Pinia store receiving it have the same name, in the singular:
event,setting,auth. - A controller changing shared data returns the changed sections (
AppRequest::only(['auth'])) or calls a store action ('event/updateEvent' => $event) instead of returning data the component copies into a store by hand. config/autoajax.phpsets'store' => true, so store data arrives under thestorekey.