Hello Forest Admin team,
I’m migrating my setup to the new Agent/Datasource architecture and need to add a collection that doesn’t live in Mongo (or any DB), but is fetched dynamically from a third-party API. In my old Forest Express/Mongoose integration I could do:
import { collection } from 'forest-express-mongoose';
collection('myapidata', {
// … fields, actions, segments …
});
router.get('/myapidata', async (req, res) => {
//code to retreive the api data
}
With the Agent, I tried to start with:
export default function configureMyApiDataCollection(agent: Agent): void {
agent.customizeCollection('myapidata', collection => {
// …
});
}
But at runtime I get errors indicating the Agent “doesn’t know” the myapidata
collection, and TypeScript complains that customizeCollection
only works for collections that were added via addDataSource
.
What’s the recommended pattern to:
- Declare a “virtual” collection whose data comes entirely from my external API
- Expose it in the Forest Admin UI with full list/detail views (and optional Smart Actions)
- Support Create/Update/Delete overrides (so CRUD operations call my API) - I used to have smart actions to do this
I’ve looked at both the Replication and Translation strategies in the docs, but I’m unclear how to wire a pure-API datasource into createAgent().addDataSource(...)
so that customizeCollection('myapidata', …)
starts working.
Could you please share a minimal example of how to do so.
Thank you in advance for your guidance!
—
Node.js Agent ^1.59.2
@forestadmin/agent
/ @forestadmin/datasource-mongoose
/ TypeScript setup