how to fetch api using http 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: How to use fetch api
async function fetchText() {
let response = await fetch('/readme.txt');
let data = await response.text();
console.log(data);
}Code language: JavaScript (javascript)