Skip to content

Instantly share code, notes, and snippets.

@hwakabh
Last active March 3, 2024 06:05
Show Gist options
  • Save hwakabh/f768bd377603d451f013e38ec3ffb19d to your computer and use it in GitHub Desktop.
Save hwakabh/f768bd377603d451f013e38ec3ffb19d to your computer and use it in GitHub Desktop.
Simple REST Client with vanilla JavaScript
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.");
{
"dependencies": {
"request": "^2.88.2"
}
}

http-tiny-client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment