The GlobalFetch interface exposes the fetch
function, which can be used to request resources.
fetch('/path/to/resource.json')
.then(response => {
if (!response.ok()) {
throw new Error("Request failed!");
}
return response.json();
})
.then(json => {
console.log(json);
});
The resolved value is a Response Object. This Object contains the body of the response, as well as it's status and headers.