Answer the question
In order to leave comments, you need to log in
How can I do it right in the request module?
Who is familiar with the request module please tell me.
const pathAPI = '/api/blog';
const requestOptions = {
url: apiOptions.server + pathAPI,
method: 'GET',
json: {}
};
const sendObj = {
title: 'My Blog'
};
request(requestOptions, function (error, response, body) {
if (error) {
console.log(error);
}
res.render('pages/blog', Object.assign({}, sendObj, body));
});
const pathAPI = ['/api/blog', '/api/avatar'];
const requestOptions = {
blog: {
url: apiOptions.server + pathAPI[0],
method: 'GET',
json: {}
},
avatar: {
url: apiOptions.server + pathAPI[1],
method: 'GET',
json: {}
}
};
Answer the question
In order to leave comments, you need to log in
Well, something like this
var locals = res.locals;
locals.title = 'My Blog';
const pathAPI = '/api/blog';
const requestOptions = {
url: apiOptions.server + pathAPI,
method: 'GET',
json: {}
};
request(requestOptions, function (error, response, body) {
if (error) {
console.log(error);
}
locals.texts = body;
// дальше смело второй запрос за аватарку и в его колбеке
request(....
...
locals.avatar = body
res.render('pages/blog');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question