Docs

Everything You Need to Know

Fetch

Intro

Truck Tank

Fetch is a new API created by the WHATWG as a simplified and lower level alternative to XHTTP requests. Fetch is built on the concept of asynch operations, something that was not taken into consideration at the time that Ajax was developed. Fetch uses promises by default. It also provides a simle and consistent interface to doing the things that Ajax requires with many lines of code. At the same time, it provides ways of customizing headers, etc. for more specialized needs. Below is an example of Fetch:

fetch('./some/url')
  .then(function(response) {
    return response.json();
  })
  .then(function(data) {
    console.log(data);
  })
  .catch(function(err){
    console.log(err);
  });

This is currently only supported in Firefox and Chrome, but Truck provides a polyfill for other browsers so you can use it today.

Please read the section on Use to learn how to use it in your app.