RequestInit
The RequestInit dictionary of the Fetch API represents the set of options that can be used to configure a fetch request.
You can pass a RequestInit object into the Request() constructor, or directly into the fetch() function call.
You can also construct a Request with a RequestInit, and pass the Request to a fetch() call along with another RequestInit. If you do this, and the same option is set in both places, then the value passed directly into fetch() is used.
Instance properties
attributionReportingOptional-
Indicates that you want the request's response to be able to register a JavaScript-based attribution source or attribution trigger.
attributionReportingis an object containing the following properties:eventSourceEligible-
A boolean. If set to
true, the request's response is eligible to register an attribution source. If set tofalse, it isn't. triggerEligible-
A boolean. If set to
true, the request's response is eligible to register an attribution trigger. If set tofalse, it isn't.
See the Attribution Reporting API for more details.
bodyOptional-
The request body contains content to send to the server, for example in a
POSTorPUTrequest. It is specified as an instance of any of the following types:See Setting a body for more details.
browsingTopicsOptional-
A boolean specifying that the selected topics for the current user should be sent in a
Sec-Browsing-Topicsheader with the associated request. cacheOptional-
The cache mode you want to use for the request. This may be any one of the following values:
default-
The browser looks in its HTTP cache for a response matching the request.
- If there is a match and it is fresh, it will be returned from the cache.
- If there is a match but it is stale, the browser will make a conditional request to the remote server. If the server indicates that the resource has not changed, it will be returned from the cache. Otherwise the resource will be downloaded from the server and the cache will be updated.
- If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
no-store-
The browser fetches the resource from the remote server without first looking in the cache, and will not update the cache with the downloaded resource.
reload-
The browser fetches the resource from the remote server without first looking in the cache, but then will update the cache with the downloaded resource.
no-cache-
The browser looks in its HTTP cache for a response matching the request.
- If there is a match, fresh or stale, the browser will make a conditional request to the remote server. If the server indicates that the resource has not changed, it will be returned from the cache. Otherwise the resource will be downloaded from the server and the cache will be updated.
- If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
force-cache-
The browser looks in its HTTP cache for a response matching the request.
- If there is a match, fresh or stale, it will be returned from the cache.
- If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
only-if-cached-
The browser looks in its HTTP cache for a response matching the request.
- If there is a match, fresh or stale, it will be returned from the cache.
- If there is no match, a network error is returned.
The
"only-if-cached"mode can only be used if the request'smodeis"same-origin". Cached redirects will be followed if the request'sredirectproperty is"follow"and the redirects do not violate the"same-origin"mode. credentialsOptional-
Controls whether or not the browser sends credentials with the request, as well as whether any