Last active
March 3, 2024 06:05
-
-
Save hwakabh/f768bd377603d451f013e38ec3ffb19d to your computer and use it in GitHub Desktop.
Simple REST Client with vanilla JavaScript
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'); | |
const headers = { | |
'Content-Type': 'application/json', | |
} | |
const url = "https://swapi.dev/api/people/1/"; | |
const wrong_url = "https://localhost:8000"; | |
console.log("Starting HTTP GET Request..."); | |
request.get(url, function(err, res, body) { | |
if (err) { | |
console.log('Failed to GET : ' + err.message); | |
return; | |
} | |
console.log(body); | |
}); | |
// note that not-sequential | |
console.log("HTTP GET Done."); | |
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
{ | |
"dependencies": { | |
"request": "^2.88.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment