Skip to content

Instantly share code, notes, and snippets.

@r-trigo
Created June 14, 2019 08:42
Show Gist options
  • Save r-trigo/ed9eadbfbde155b4973eb3047256caf4 to your computer and use it in GitHub Desktop.
Save r-trigo/ed9eadbfbde155b4973eb3047256caf4 to your computer and use it in GitHub Desktop.
Chaining HTTP requests with request-promise package
const rp = require('request-promise');
go()
function go() {
var options = {
uri: 'https://jsonplaceholder.typicode.com/todos/1',
json: true
};
let m = 0
let g = 0
rp(options)
.then(data1 => {
m = data1.id
})
.then(() => {
options.uri = 'https://jsonplaceholder.typicode.com/todos/2'
rp(options)
.then(data2 => {
console.log(options.uri)
g = data2.id
console.log(m, ' e ', g)
})
})
.catch(err => {
console.log(err)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment