Write handlers
Implementation
Example
const axios = require('axios');
const { createReplicaDataSource } = require('@forestadmin/datasource-replica');
const url = 'https://jsonplaceholder.typicode.com';
const myCustomDataSource = createReplicaDataSource({
// ... Implement record synchronization as explained in the previous sections
// Create the record in the target API
createRecordHandler: async (collectionName, record) => {
const response = await axios.post(`${url}/${collectionName}`, record);
// Return the record as it was created in the target API
return response.data;
},
// Update the record in the target API
createRecordHandler: async (collectionName, record) => {
await axios.put(`${url}/${collectionName}/${record.id}`, record);
},
// Delete the record in the target API
createRecordHandler: async (collectionName, record) => {
await axios.delete(`${url}/${collectionName}/${record.id}`);
},
});Last updated