Created
June 14, 2019 08:42
-
-
Save r-trigo/ed9eadbfbde155b4973eb3047256caf4 to your computer and use it in GitHub Desktop.
Chaining HTTP requests with request-promise package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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