This question is a continuation of the question below.
How do I handle the REST API in node.js in Marklogic Grove?
I was able to implement a sample REST API that can be called when authenticated with Grove, as shown below.
middle-tier/routes/index.js
const authProvider = require('../../grove-node-server-utils/auth-helper');
router.get('/my-rest-api/bar',(req, res) => {
const response = {status : "success"};
authProvider.isAuthenticated(req,res,()=>{
res.send(response);
});
});
Next, I want to call the MarkLogic API from within the my-rest-api. I wrote the following through trial and error, but an error occurs.How should I write it?
middle-tier/routes/index.js
const authProvider = require('../../grove-node-server-utils/auth-helper');
const backend = require('../../grove-node-server-utils/backend');
router.get('/my-rest-api/bar',(req, res) => {
const myResponse = {status : "success!!"};
console.log("start");
const backendOptions = {
method: 'GET',
path: '/v1/resources/myMarkLogicAPI?p1=test'
};
authProvider.isAuthenticated(req,res,()=>{
console.log("preprocessing");
backend.call(req, backendOptions, () => {
console.log("postprocessing")
res.send(myResponse);
});
});
});
The error message is: {"message":"TypeError: Cannot convert undefined or null to object"}