type opaque response code example
Example 1: fetch api
const url = "http://dummy.restapiexample.com/api/v1/employees";
fetchurl()
.then(res => {
console.log(res);
})
.catch(err => {
console.log('Error: ${err}' );
});
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( );