in which fomat data is fetched from api code example
Example 1: fetch api
const url = "http://dummy.restapiexample.com/api/v1/employee/40";
fetch(url)
.then( res => {
if (res.ok) {
return res.json( );
} else {
return Promise.reject(res.status);
}
})
.then(res => console.log(res))
.catch(err => console.log('Error with message: ${err}') );
Example 2: fetch api
const url = "http://dummy.restapiexample.com/api/v1/employees";
fetchurl()
.then(res => {
console.log(res);
})
.catch(err => {
console.log('Error: ${err}' );
});