Skip to content

Instantly share code, notes, and snippets.

@lebowvsky
Created June 15, 2020 08:22
Show Gist options
  • Save lebowvsky/8f713c9edce98a15661ad18b734587f5 to your computer and use it in GitHub Desktop.
Save lebowvsky/8f713c9edce98a15661ad18b734587f5 to your computer and use it in GitHub Desktop.
JavaScript Asynchrone 1
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