July 2018
Intermediate to advanced
354 pages
8h 51m
English
The Request constructor has the same two parameters as the fetch method has, a URL and option initialization object. The following code modifies the fetch example to use a custom request object:
var myRequest = new Request("./api/podcast/" + id + ".json");
fetch(myRequest).then(function(response) {
if (response.status !== 200) {
console.log('Status Code: ' + response.status);
return;
}
return response.json();
}).then(function(response) {
console.log(data);
});
You can do much more than just create a request object from a URL. You can craft a request using various options. While most requests are simple GET requests, there are many times where you need to craft something custom. The request object gives you the flexibility ...
Read now
Unlock full access