Skip to content

FetchAPI

Types

bodyInit

type bodyInit

Module

There are methods and helpers defined in BodyInit .

formData

Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data". See FormData on MDN

type formData = {}

Module

There are methods and helpers defined in FormData .

formDataEntryValue

type formDataEntryValue = WebAPI.Prelude.any

headers

This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs.  You can add to this using methods like append() (see Examples.) In all methods of this interface, header names are matched by case-insensitive byte sequence. See Headers on MDN

type headers = {}

Module

There are methods and helpers defined in Headers .

headersInit

type headersInit

Module

There are methods and helpers defined in HeadersInit .

referrerPolicy

type referrerPolicy =
| @as("no-referrer") NoReferrer
| @as("no-referrer-when-downgrade") NoReferrerWhenDowngrade
| @as("origin") Origin
| @as("origin-when-cross-origin") OriginWhenCrossOrigin
| @as("same-origin") SameOrigin
| @as("strict-origin") StrictOrigin
| @as("strict-origin-when-cross-origin") StrictOriginWhenCrossOrigin
| @as("unsafe-url") UnsafeUrl

request

This Fetch API interface represents a resource request. See Request on MDN

type request = {
method: string,
url: string,
headers: headers,
destination: requestDestination,
referrer: string,
referrerPolicy: referrerPolicy,
mode: requestMode,
credentials: requestCredentials,
cache: requestCache,
redirect: requestRedirect,
integrity: string,
keepalive: bool,
signal: WebAPI.EventAPI.abortSignal,
body: Null.t<WebAPI.FileAPI.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 URL of request as a string. Read more on MDN

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

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 URL 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

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

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

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

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

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

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< WebAPI.FileAPI.readableStream< array< int > > >
bodyUsed
bool

Module

There are methods and helpers defined in Request .

requestCache

type requestCache =
| @as("default") Default
| @as("force-cache") ForceCache
| @as("no-cache") NoCache
| @as("no-store") NoStore
| @as("only-if-cached") OnlyIfCached
| @as("reload") Reload

requestCredentials

type requestCredentials =
| @as("include") Include
| @as("omit") Omit
| @as("same-origin") SameOrigin

requestDestination

type requestDestination =
| @as("audio") Audio
| @as("audioworklet") Audioworklet
| @as("document") Document
| @as("embed") Embed
| @as("font") Font
| @as("frame") Frame
| @as("iframe") Iframe
| @as("image") Image
| @as("manifest") Manifest
| @as("object") Object
| @as("paintworklet") Paintworklet
| @as("report") Report
| @as("script") Script
| @as("sharedworker") Sharedworker
| @as("style") Style
| @as("track") Track
| @as("video") Video
| @as("worker") Worker
| @as("xslt") Xslt

requestInfo

type requestInfo = WebAPI.Prelude.any

requestInit

type requestInit = {
mutable method?: string,
mutable headers?: headersInit,
mutable body?: bodyInit,
mutable referrer?: string,
mutable referrerPolicy?: referrerPolicy,
mutable mode?: requestMode,
mutable credentials?: requestCredentials,
mutable cache?: requestCache,
mutable redirect?: requestRedirect,
mutable integrity?: string,
mutable keepalive?: bool,
mutable signal?: Null.t<WebAPI.EventAPI.abortSignal>,
mutable priority?: requestPriority,
mutable window?: Null.t<unit>,
}

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 URL, "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< WebAPI.EventAPI.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.

requestMode

type requestMode =
| @as("cors") Cors
| @as("navigate") Navigate
| @as("no-cors") NoCors
| @as("same-origin") SameOrigin

requestPriority

type requestPriority =
| @as("auto") Auto
| @as("high") High
| @as("low") Low

requestRedirect

type requestRedirect =
| @as("error") Error
| @as("follow") Follow
| @as("manual") Manual

response

This Fetch API interface represents the response to a request. See Response on MDN

type response = {
type_: responseType,
url: string,
redirected: bool,
status: int,
ok: bool,
statusText: string,
headers: headers,
body: Null.t<WebAPI.FileAPI.readableStream<array<int>>>,
bodyUsed: bool,
}

Record fields

url
string
redirected
bool
status
int
statusText
string
body
Null.t< WebAPI.FileAPI.readableStream< array< int > > >
bodyUsed
bool

Module

There are methods and helpers defined in Response .

responseInit

type responseInit = {
mutable status?: int,
mutable statusText?: string,
mutable headers?: headersInit,
}

Record fields

status
option< int >
statusText
option< string >
headers
option< headersInit >

responseType

type responseType =
| @as("basic") Basic
| @as("cors") Cors
| @as("default") Default
| @as("error") Error
| @as("opaque") Opaque
| @as("opaqueredirect") Opaqueredirect

urlSearchParams

type urlSearchParams = {size: int}

Record fields

size
int