I wanna make a GET request from Bluemix API with request-promise and the promise doesn't do anything. I'm able to get data, but It's asynchronous. It's possible that I'm just misunderstanding some things. Does anyone know how to make it wait few seconds?
var request = require('request');
var rp = require('request-promise');
var username = "username";
var password = "password";
var location = 'location';
var language = 'cs-CZ';
var units = 'm';
var locationURL = 'https://twcservice.mybluemix.net/api/weather/v3/location/search'
console.log('url:', locationURL);
var qs = {
language: language,
query: location
};
var options = {
uri: locationURL,
qs: qs,
auth: {
username: username,
password: password
},
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
var jsonPosition = {
location: []
};
rp(options)
.then(function (repos) {
var jsonPosition = repos;
console.log(jsonPosition); //I can receive the data, but can't work with them
return repos;
})
.catch(function (err) {
// API call failed...
});
console.log('options:', options);
//console.log(jsonPosition);
I can get repos (jsonPosition), which is this code below, but It pop up one second after "//console.log(jsonPosition);" so I can't use it in code. I need to find way how to slow it down.
{ location:
{ address:
[ 'Praha, Praha, Česko',
'Praha, Česko',
'Praha, Banskobystrický kraj, Slovensko' ],
adminDistrict: [ 'Praha', 'Praha', 'Banskobystrický kraj' ],
adminDistrictCode: [ null, null, null ],
city: [ 'Praha', null, 'Praha' ],
country: [ 'Česko', 'Česko', 'Slovensko' ],
countryCode: [ 'CZ', 'CZ', 'SK' ],
displayName: [ 'Praha', 'Praha', 'Praha' ],
ianaTimeZone: [ 'Europe/Prague', 'Europe/Prague', 'Europe/Bratislava' ],
latitude: [ 50.089, 50.06, 48.381 ],
locale: [ [Object], [Object], [Object] ],
longitude: [ 14.421, 14.446, 19.527 ],
neighborhood: [ null, null, null ],
placeId:
[ '81cbe8a06fd80171651aef7a414bce1e867b5282a9600401442fc37ce54868ce',
'2496f2ca6bdc13f9c1b4e1d83e78a40602f387ae3244fba51f059be17d224eb1',
'9294b774d158cdfad77c4a20c39559523ce0628e89025917922169775db07ef3' ],
postalCode: [ null, null, null ],
postalKey: [ null, null, null ] } }