Created
December 27, 2020 21:25
-
-
Save reime005/b57e896f4e23f3e77c70c89f2fc8791b to your computer and use it in GitHub Desktop.
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 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