How to Use the JavaScript Fetch API to Get Data

JavaScript
const GetData = [];
  useEffect(() => {
    fetch(API_URL)
      .then((res) => res.json())
      .then((data) => {
        GetModesData.push(...data);
        setDataState(GetData.map((d) => d.modeName));
      });
  }, []);fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));
const GetData = [];
  useEffect(() => {
    fetch(API_URL)
      .then((res) => res.json())
      .then((data) => {
        GetModesData.push(...data);
        setDataState(GetData.map((d) => d.modeName));
      });
  }, []);
fetch('http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=221380')
    .then(function(response) {
        return response.json();
    })
    .then(function(myJson) {
        console.log(JSON.stringify(myJson));
    });
fetch('https://api.github.com/users/manishmshiva', {
  method: "GET",
  headers: {"Content-type": "application/json;charset=UTF-8"}
})
.then(response => response.json()) 
.then(json => console.log(json)); 
.catch(err => console.log(err));var myHeaders = new Headers();

var myInit = { method: 'GET',
               headers: myHeaders,
               mode: 'cors',
               cache: 'default' };

fetch('flowers.jpg',myInit)
.then(function(response) {
  return response.blob();
})
.then(function(myBlob) {
  var objectURL = URL.createObjectURL(myBlob);
  myImage.src = objectURL;
});


Source

Also in JavaScript: