I know that Fetch API uses Promise
s and both of them allow you to do AJAX requests to a server.
I have read that Fetch API has some extra features, which aren't available in XMLHttpRequest
(and in the Fetch API polyfill, since it's based on XHR
).
What extra capabilities does the Fetch API have?
There are a few things that you can do with fetch and not with XHR:
no-cors
requests, getting a response from a server that doesn't implement CORS. You can't access the response body directly from JavaScript, but you can use it with other APIs (e.g. the Cache API);There are a couple of things that you can do with XHR that you can't do yet with fetch, but they're going to be available sooner or later (read the "Future improvements" paragraph here: https://hacks.mozilla.org/2015/03/this-api-is-so-fetching/):
This article https://jakearchibald.com/2015/thats-so-fetch/ contains a more detailed description.