Member-only story
Javascript Fetch API: The XMLHttpRequest evolution
4 min readSep 14, 2019

The Javascript Fetch API is the current standard to make asynchronous HTTP Requests. To anyone who used XMLHttpRequest and Jquery.ajax(), this new API provides more powerful and flexible features.
The main features of the Javascript Fetch API are:
- Generic definition of
Request
andResponse
objects - More control over request properties and content
- More details about response properties and content.
- Interaction with other Web APIs (for example: Cache API, Blob API)
- Better control and setup for CORS-related requests
- Implemented for Web pages as
window.fetch()
and for Web workers withWorkerGlobalScope.fetch()
What’s different
Implementation of XMLHttpRequest
and fetch()
differ in a couple of points, in order to allowfetch()
better control over the request and response:
- Promises returned from
fetch()
will not fail in any HTTP error status (even HTTP 404 or 500) - It will resolve successfully with
ok
status set tofalse
- It will only fail after a network failure or if the request couldn’t be completed.
- By default,
fetch()
will not send cookies or credentials…