HTTP with the fetch API

suggest change

It should be noted that Fetch does not support progress callbacks. See: https://github.com/github/fetch/issues/89.

The alternative is to use XMLHttpRequest https://developer.mozilla.org/en-US/docs/Web/Events/progress.

fetch resolves to a Response, not parsed JSON. form and onLogin come from the surrounding screen.

fetch('https://mywebsite.com/mydata.json')
  .then(response => response.json())
  .then(json => console.log(json));

fetch('/login', {
  method: 'POST',
  body: form,
  mode: 'cors',
  cache: 'default',
}).then(
  response => response.json().then(session => onLogin(session)),
  failure => console.error(failure)
);

More details about fetch can be found at MDN

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents