Skip to content

Request

Types

bodyInit

type bodyInit = BodyInit.t

headersInit

type headersInit = HeadersInit.t

requestInit

type requestInit = FetchTypes.requestInit

Record fields

method
option< string >

A string to set request's method.

headers
option< headersInit >

A Headers object, an object literal, or an array of two-item arrays to set request's headers.

body
option< bodyInit >

A BodyInit object or null to set request's body.

referrer
option< string >

A string whose value is a same-origin WebApiURL, "about:client", or the empty string, to set request's referrer.

referrerPolicy
option< referrerPolicy >

A referrer policy to set request's referrerPolicy.

mode
option< requestMode >

A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode.

credentials
option< requestCredentials >

A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials.

cache
option< requestCache >

A string indicating how the request will interact with the browser's cache to set request's cache.

redirect
option< requestRedirect >

A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect.

integrity
option< string >

A cryptographic hash of the resource to be fetched by request. Sets request's integrity.

keepalive
option< bool >

A boolean to set request's keepalive.

signal
option< Null.t< EventTypes.abortSignal > >

An AbortSignal to set request's signal.

priority
option< requestPriority >
window
option< Null.t< unit > >

Can only be null. Used to disassociate request from any Window.

t

type t = FetchTypes.request = {
method: string,
url: string,
headers: FetchTypes.headers,
destination: FetchTypes.requestDestination,
referrer: string,
referrerPolicy: FetchTypes.referrerPolicy,
mode: FetchTypes.requestMode,
credentials: FetchTypes.requestCredentials,
cache: FetchTypes.requestCache,
redirect: FetchTypes.requestRedirect,
integrity: string,
keepalive: bool,
signal: EventTypes.abortSignal,
body: Null.t<FileTypes.readableStream<array<int>>>,
bodyUsed: bool,
}

Record fields

method
string

Returns request's HTTP method, which is "GET" by default. Read more on MDN

url
string

Returns the WebApiURL of request as a string. Read more on MDN

headers
FetchTypes.headers

Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. Read more on MDN

destination
FetchTypes.requestDestination

Returns the kind of resource requested by request, e.g., "document" or "script". Read more on MDN

referrer
string

Returns the referrer of request. Its value can be a same-origin WebApiURL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the Referer header of the request being made. Read more on MDN

referrerPolicy
FetchTypes.referrerPolicy

Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. Read more on MDN

mode
FetchTypes.requestMode

Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. Read more on MDN

credentials
FetchTypes.requestCredentials

Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Read more on MDN

cache
FetchTypes.requestCache

Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. Read more on MDN

redirect
FetchTypes.requestRedirect

Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. Read more on MDN

integrity
string

Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] Read more on MDN

keepalive
bool

Returns a boolean indicating whether or not request can outlive the global in which it was created. Read more on MDN

signal
EventTypes.abortSignal

Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. Read more on MDN

body
Null.t< FileTypes.readableStream< array< int > > >
bodyUsed
bool

Values

arrayBuffer

let arrayBuffer: t => promise<ArrayBuffer.t>

Parameters

t

Return type

promise< Stdlib.ArrayBuffer.t >

blob

let blob: t => promise<Blob.t>

Parameters

t

Return type

promise< Blob.t >

bytes

let bytes: t => promise<array<int>>

Parameters

t

Return type

promise< array< int > >

clone

let clone: t => t

Parameters

t

Return type

t

formData

let formData: t => promise<FormData.t>

Parameters

t

Return type

promise< FormData.t >

fromRequest

let fromRequest: (t, ~init: requestInit=?) => t

Parameters

t option< requestInit >

Return type

t

fromURL

let fromURL: (string, ~init: requestInit=?) => t

Parameters

string option< requestInit >

Return type

t

json

let json: t => promise<JSON.t>

Parameters

t

Return type

promise< Stdlib.JSON.t >

text

let text: t => promise<string>

Parameters

t

Return type

promise< string >