javascript fetch api 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
const url = 'http://dummy.restapiexample.com/api/v1/employees';
const fetchUsers = async () => {
try {
const res = await fetch(url);
if (!res.ok) {
throw new Error(res.status);
}
const data = await res.json();
console.log(data);
}
catch (error) {
console.log(error);
}
}
fetchUsers( );