js fetch request 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: javascript fetch json

fetch('./yourjson.json')
  .then((response) => response.json())
  .then((data) => {
  	console.log(data);
  })

Example 4: fetch api javascript

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

Example 5: http request javascript fetch

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

Example 6: .fetch method

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