Skip to content

Instantly share code, notes, and snippets.

@reime005
Created December 27, 2020 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reime005/b57e896f4e23f3e77c70c89f2fc8791b to your computer and use it in GitHub Desktop.
Save reime005/b57e896f4e23f3e77c70c89f2fc8791b to your computer and use it in GitHub Desktop.
const fetch = require("node-fetch"); // npm install node-fetch
const getSomeData = async () => {
try {
const response = await fetch('https://swapi.co/api/people/?search=r2');
if (response.ok) {
return await response.json();
} else {
throw response.status;
}
} catch (error) {
throw error;
}
}
getSomeData()
.then(json => console.log(json.results[0].name))
.catch(error => console.error(error))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment