fetch method

Initiates the fetching of a resource.

Syntax

*object.*fetch(input, init)

Parameters

  • input
    Type: USVString or Request

    Defines the resource that will be fetched. This can either be a Request object or a USVString specifying the URL of the resource.

  • init [optional]
    Type: RequestInit

    An options object that specifies custom settings as defined in the RequestInit dictionary.

Return value

Type: Promise<Response>

A promise for a Response object.

Standards information

Remarks

Dictionary of RequestInit members:

Dictionary Member Type Description
method ByteString The method of the request.
headers HeaderInit A headers object to be added to the request.
body BodyInit A body to be added to the request.
referrer USVString The referrer of the request.
referrerPolicy ReferrerPolicy The referrer policy of the request.
mode RequestMode The mode of the request.
credentials RequestCredentials The credentials of the request.
cache RequestCache The cache mode of the request.
redirect RequestRedirect The redirect mode of the request.
integrity DOMString The integrity metadata of the request.

 

RequestType enumeration:

  • ""
  • "audio"
  • "font"
  • "image"
  • "script"
  • "track"
  • "video"

RequestDestination enumeration:

  • ""
  • "document"
  • "sharedworker"
  • "subresource"
  • "unknown"
  • "worker"

RequestMode enumeration:

  • "navigate"
  • "same-origin"
  • "no-cors"
  • "cors"

RequestCredentials enumeration:

  • "omit"
  • "same-origin"
  • "include"

RequestCache enumeration:

  • "default"
  • "no-store"
  • "reload"
  • "no-cache"
  • "force-cache"

RequestRedirect enumeration:

  • "follow"
  • "error"
  • "manual"

See also

WorkerGlobalScope

Window