Fetch is the native AJAX API to replace jQuery.get()

As a term AJAX has been around for over a decade now. While many still relate to it as rich and fluid interfaces, the real deal is the possibility of making asynchronous requests to the server from the browser.

As browsers evolved the XMLHttpRequest API used for AJAX did not not evolve. This is why many developers still rely on including the whole jQuery library just to abstract asynchronous HTTP Request. jQuery has a great and simple to use API for many things, but including it just for AJAX is overkill.

Finally the Web API has a new native alternative available. This is known as the Fetch API and offers a very simple way of getting content from the server with JavaScript in the browser. The API is a high level one that has a generic definition of HTTP Request and Response objects.

To anyone used to working with the HTTP, the concepts are immediately familiar:

GlobalFetch : Contains the fetch() method used to fetch a resource.

: Contains the fetch() method used to fetch a resource. Headers : Represents response/request headers, allowing you to query them and take different actions depending on the results.

: Represents response/request headers, allowing you to query them and take different actions depending on the results. Request : Represents a resource request.

: Represents a resource request. Response: Represents the response to a request.

In addition to standard features developers would expect, the Fetch API definition handles closely related concepts such as CORS (Cross-origin resource sharing) and HTTP origin headers. The fetch resouce is available in the browser's standard window object and has only a single mandatory argument - the request URL.

The fetch method returns a JavaScript promise that makes it convenient to work with the asynchronous nature of HTTP requests in the browser context. Once the response is received, there are a number of methods available in the object.

Browser support for the Fetch API is very good with evergreen browsers such as Chrome, Edge, Firefox and Opera already supporting the feature. Internet Explorer does not support the API, but there is a fetch API polyfill that can be used for it.