Using the Fetch API
We have already seen the Fetch API being used in Chapter 4, Service Workers – Notification, Synchronization, and Our Podcast App, so let's do a quick review. Fetch is a modern replacement for XMLHttpRequest. It is asynchronous, relying on promises, and provides a more streamline interface to manage dynamic requests. You can customize requests by creating custom Request and header objects. Service workers rely on Fetch to make network requests.
The fetch() method takes two parameters, the URL that you are requesting (or a request object) and an options object. This method returns a promise object.
There are also some differences from how you may be accustomed to making AJAX requests. Fetch does not usually throw an exception ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access