Created
June 15, 2020 08:22
-
-
Save lebowvsky/8f713c9edce98a15661ad18b734587f5 to your computer and use it in GitHub Desktop.
JavaScript Asynchrone 1
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 request = require('request'); | |
request('https://swapi.dev/api/people/1/', function (error, response, body) { | |
console.error('error:', error); // Print the error if one occurred | |
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received | |
const luke = JSON.parse(body); | |
console.log(luke); | |
request(luke.films[0], function (err, res, bod) { | |
console.error('error:', err); // Print the error if one occurred | |
console.log('statusCode:', res && res.statusCode); // Print the response status code if a response was received | |
const film = JSON.parse(bod); | |
console.log(film.title); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment