fetch api xml code example
Example 1: fetch api
// Fetch and Async/Await
const url = 'http://dummy.restapiexample.com/api/v1/employees';
const fetchUsers = async () => {
try {
const res = await fetch(url);
// check for 404 error
if (!res.ok) {
throw new Error(res.status);
}
const data = await res.json();
console.log(data);
}
// catch block for network errors
catch (error) {
console.log(error);
}
}
fetchUsers( );
Example 2: xml http request fetch
fetch('my/url/').then(respone()=>{
console.log(response);
}