This is probably a very basic question but none of the solutions online are helping. I am trying to make a post call
/* eslint-disable no-undefined */
let req = require('request');
function mutate(body) {
return body;
}
function post(request) {
let config = request.server.app.config;
let payload = request.payload;
let imageFile = '';
let options = {
method: 'POST',
url: `${config.get('api.baseUrl')}/imageUpload`,
headers: {
'Accept': '*/*',
'cache-control': 'no-cache'
},
formData:
{
file: imagefile
}
};
return req(options, (error, response, body) => {
if (error) {
throw new Error(error);
}
request.log(response);
return body;
});
}
module.exports = {
post
};
The response that is being printed is correct. The value is returned before the actual call completes. What is the correct method to return the actual response