...
.then(resp => { //process response// } );
Digest-Fetch
Digest-fetch is a plugin used for fetch/node-fetch. We make use of it for the event handler functions. It also supports http basic authentication.
const sdk = require('kinvey-flex-sdk');
const DigestFetch = require('digest-fetch');
Class CamundaService {
constructor(){
this.client = new DigestFetch(userName, password);
this.logger = flex.logger;
}
getAll (context, complete, modules) {
this.logger.info('getAll Context:' + JSON.stringify(context));
const backendUrl = "url to camunda backend";
this.client.fetch(backendUrl)
.then(response => response.json())
.then(data => {
data.forEach(item => {
item._id = item.id;
});
complete().setBody(data).ok().next();
})
.catch(e => console.error(e));
}
}
sdk.service((err, flex) => {
const data = flex.data; //get data object
const flexLogger = flex.logger; //get logger
const camundaFlexServive = data.serviceObject('task'); //get service object from data object
camundaService = new CamundaService(key, flex); //instantiate new service class
camundaFlexServive.onGetAll(camundaService.getAll.bind(camundaService)); //bind handler function to getAll event
}