Fetch

During its early years, using the raw XMLHttpRequest object was rather difficult for most web developers, and could easily lead to a large amount of JavaScript source code which was often difficult to read and understand: these issues were eventually solved by the superstructures that were brought by libraries such as jQuery and the like, but at the cost of some inevitable code (and resource) overheads.

The Fetch API was released to address such issues in a cleaner way, using a built-in, promise-based approach, which could be used to perform the same asynchronous server requests in an easy way, without requiring third-party libraries.

Here's an example of an HTTP request using XHR:

var oReq = new XMLHttpRequest();oReq.onload = function() ...

Get ASP.NET Core 3 and Angular 9 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.