Requesting the Backend
All requests to the backend should utilize the `agent` in the frontend.
Last updated
Was this helpful?
All requests to the backend should utilize the `agent` in the frontend.
Last updated
Was this helpful?
The agent
is located at /packages/utility/agent.ts
To include other objects when requesting data, for example, to get the likes associated with a given comment, we can specify the fields to populate in the URL request parameters
If at all possible, we should avoid use populate=deep
, because it is very resource intensive
The agent uses a cookie for handling authentication to the backend.
No credentials need to be passed in to the agent by developers, as it will use the existing cookie automatically.
Each model in our database should have a corresponding object in the agent.
For example, likes
has an object in the agent
which allows us to get, put, post, or delete likes
Developers need to add new objects to the agent whenever new models are added to the database.
Because agent
is written in TypeScript, we also need to make sure the database models, located in /packages/models/
are in sync with the current database models in the backend (Strapi)
Because the data returned by Strapi contains some extra fields and nested objects, it is suggested to "clean" the response data so it is formatted in the same way as our TypeScript models
To do this, we can use a helper method, such as the one located at /apps/ideaspace/src/utils/StrapiHelper.js