Skip to main content

Module fetch

Module fetch 

Source
Expand description

The WHATWG Fetch globals: fetch, Headers, Request, Response, Blob, FormData, AbortController and AbortSignal.

fetch is not a re-implementation of an HTTP client: it drives the SAME exchange http.request/https.request already perform (http::exchange / https::exchange), on a background thread, and hands the parsed result back over the host’s I/O channel — the pattern every other async native in this frontend uses. That keeps one HTTP/1.1 wire implementation, one chunked decoder and one TLS configuration in the process.

A body is held as raw BYTES (@@body, a JS array of byte numbers) rather than as a string, so arrayBuffer()/bytes() are exact for a binary response and text() decodes UTF-8 once, at the point the caller asks for text. A Response is fully buffered by the time the promise settles, so the body accessors are already-settled promises — the streaming body ReadableStream is the one part of the interface this does not provide.

Constants§

ABORT_CONTROLLER_METHODS
ABORT_SIGNAL_METHODS
ABORT_SIGNAL_STATICS
BLOB_METHODS
CLASSES
The classes this module constructs, as bare globals.
FORM_DATA_METHODS
HEADERS_METHODS
REQUEST_METHODS
RESPONSE_METHODS
RESPONSE_STATICS

Functions§

abort_controller_call
abort_signal_call
abort_signal_static
AbortSignal.abort(reason) / AbortSignal.timeout(ms).
body_call
The body accessors shared by Response, Request and Blob. Each answers a settled Promise, because the body is already fully buffered.
construct
construct_abort_controller
construct_blob
construct_file
new File(parts, name[, options]) — a Blob that also carries a name.
construct_form_data
construct_headers
new Headers(init). init is another Headers, an array of [name, value] pairs, or a plain object.
construct_request
new Request(input, init).
construct_response
new Response(body, init).
fetch
fetch(input[, init]) — a Promise for a fully buffered Response.
fire_timeout_abort
Fire an AbortSignal.timeout deadline: abort the signal at heap index idx with a TimeoutError. Reached from the @@aborttimeout:<idx> thunk.
form_data_call
headers_call
instance_call
is_class
methods_for
new_abort_signal
static_call
The static methods of these classes (Response.json, AbortSignal.abort, …).