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

attributionReporting Optional

Indicates that you want the request's response to be able to register a JavaScript-based attribution source or attribution trigger. attributionReporting is 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 to false, it isn't.

triggerEligible

A boolean. If set to true, the request's response is eligible to register an attribution trigger. If set to false, it isn't.

See the Attribution Reporting API for more details.

body Optional

The request body contains content to send to the server, for example in a POST or PUT request. It is specified as an instance of any of the following types:

See Setting a body for more details.

browsingTopics Optional

A boolean specifying that the selected topics for the current user should be sent in a Sec-Browsing-Topics header with the associated request.

cache Optional

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's mode is "same-origin". Cached redirects will be followed if the request's redirect property is "follow" and the redirects do not violate the "same-origin" mode.

credentials Optional

Controls whether or not the browser sends credentials with the request, as well as whether any