fetch function in js code example

Example 1: javascript fetch api

fetch('http://example.com/movies.json')
  .then((response) => {
    return response.json();
  })
  .then((data) => {
    console.log(data);
  });

Example 2: fetch api javascript

fetch('http://example.com/songs')
	.then(response => response.json())
	.then(data => console.log(data))
	.catch(err => console.error(err));

Example 3: fetch api in javascript

// GET Request.
fetch('https://jsonplaceholder.typicode.com/users')
    // Handle success
    .then(response => response.json())  // convert to json
    .then(json => console.log(json))    //print data to console
    .catch(err => console.log('Request Failed', err)); // Catch errors

Example 4: fetch in javascript

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));