How to do HTTP GET request in JavaScript?

In JavaScript, we can do HTTP GET requests in multiple ways. We can use the new window.fetch to do the GET request. It is a cleaner replacement for XMLHttpRequest that makes use of ES6 promises.

Following is an example of fetch

fetch(url).then(function(response) {
  return response.json();
}).then(function(data) {
  console.log(data);
}).catch(function() {
  console.log("Booo");
});

By using async/await of ES7 we can make it synchronous. async/await makes the fetch call a lot simpler. See the code segment below:

async function fetchAsync (url) {
  const response = await fetch(url);
  const data = await response.json();
  return data;
}