Node.js chained HTTP requests using promises through the request-promise-native module
This file contains 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-native"); | |
rp("https://www.andreasjakl.com/") | |
.then(function(response) { | |
// Start second request, e.g., based on results of first request | |
console.log("Response length: ", response.length); | |
if (response.length > 100) { | |
return rp("https://www.andreasjakl.com/wp-content/uploads/2018/08/arcore-anchors.gif"); | |
} | |
}) | |
.then(function(response2) { | |
// Process response of 2nd request | |
console.log("Data: ", response2.substring(0,10)); | |
}) | |
.catch(function(error) { | |
console.log("Error: ", error); | |
}); | |
console.log("Starting..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment