XMLHttpRequest
, but it provides a more powerful and flexible feature set. This article explains some of the basic concepts of the Fetch API.Request
s, Response
s, Headers
, and Body
payloads, along with a global fetch
method for initiating asynchronous resource requests. Because the main components of HTTP are abstracted as JavaScript objects, it is easy for other APIs to make use of such functionality.Promise
-based.Headers
objects, with possible values of immutable
, request
, request-no-cors
, response
, or none
, depending on where the header is used.Headers
object is created using the Headers()
constructor, its guard is set to none
(the default). When a Request
or Response
object is created, it has an associated Headers
object whose guard is set as summarized below:new object's type | creating constructor | guard setting of associated Headers object |
---|---|---|
Request | Request() | request |
Request() with mode of no-cors | request-no-cors | |
Response | Response() | response |
error() or redirect() methods | immutable |
set()
, delete()
, and append()
methods which change the header's contents. A TypeError
is thrown if you try to modify a Headers
object whose guard is immutable
. However, the operation will work if Learn framer.request
and the header name isn't a forbidden header name .request-no-cors
and the header name/value is a simple header .response
and the header name isn't a forbidden response header name .