Skip to content

Fetch

How Elide supports fetch, Request, Response, Headers, FormData, Blob and File: supported URL schemes, no CORS or HTTP cache, the default User-Agent and response decompression.

On this page

fetch, Blob, File, Headers, FormData, Request, and Response are globals with the Fetch Standard API: bodies, streams, clone(), Response.json(), AbortSignal and subresource integrity.

Example

js
// fetch.mjs
const form = new FormData();
form.append("name", "elide");
form.append("file", new File(["hello"], "hello.txt", { type: "text/plain" }));

const request = new Request("https://example.com/upload", { method: "POST", body: form });
console.log(request.method, request.headers.get("content-type").split(";")[0]);

const response = Response.json({ ok: true }, { status: 201, headers: { "x-id": "7" } });
console.log(response.status, response.headers.get("x-id"), JSON.stringify(await response.json()));

const blob = new Blob(["a", "b", "c"], { type: "text/plain" });
console.log(blob.size, await blob.slice(1).text());
utf-8 · js · Lines: 13

elide run fetch.mjs prints:

text
POST multipart/form-data
201 7 {"ok":true}
3 bc
utf-8 · text · Lines: 3

Differences from browsers

  • fetch accepts http: and https: URLs; data: and blob: URLs reject with unsupported URL scheme.
  • There is no origin: mode, credentials, referrer and keepalive are accepted and ignored, and no CORS checks, preflights, cookies or Referer headers are applied.
  • Requests send User-Agent: Elide/<version> and Accept: */* unless you set those headers. ELIDE_HTTP_USER_AGENT changes the default user agent; its value must be printable ASCII.
  • Gzip, deflate, Brotli, and Zstandard responses are decoded; response headers still describe the encoded body.
  • An explicit Accept-Encoding header is sent as given; range requests default to identity.
  • fetch(url, { decompress: false }) sends Accept-Encoding: identity and returns any encoded body unchanged.
  • A malformed compressed body rejects.
  • There is no HTTP cache: conditional headers are sent as given, and a 304 has headers and no body.
  • Headers applies the request, response, no-CORS and immutable guards; iteration lowercases and sorts names and keeps Set-Cookie values separate.
  • Integrity checks buffer up to 100 MiB before the response resolves.
  • HTTP/1.1, HTTP/2, and HTTP proxies (including HTTPS CONNECT) work; authenticated proxies fail.
  • Certificates and hostnames are validated; for trust settings, see Runtime Environment Variables.

To serve HTTP, see Elide.serve or node:http.

Samples

Reference

Status: Full · 1,455 of 2,511 suite tests pass (57.9%) · since 1.1.0

Exports

ExportKindStatusNotes
HeadersclassFullappend(), delete(), get(), getSetCookie(), has(), set(), iteration
RequestclassFullmethod, url, headers, destination, referrer, referrerPolicy, mode, credentials, cache, redirect, integrity, keepalive, signal, duplex, clone(), body, bodyUsed, arrayBuffer(), blob(), bytes(), formData(), json(), text()
ResponseclassFullResponse.error(), Response.redirect(), Response.json(), type, url, redirected, status, ok, statusText, headers, clone(), body, bodyUsed, arrayBuffer(), blob(), bytes(), formData(), json(), text()
BlobclassFullsize, type, slice(), text(), arrayBuffer(), bytes(), stream()
FileclassFullname, lastModified
FormDataclassFullappend(), delete(), get(), getAll(), has(), set(), iteration

Tests: wpt-wintertc fetch: 1,455 pass, 1,043 fail, 13 error, 400 skipped. Failing: fetch/api/basic/request-forbidden-headers.any.js (96), fetch/api/redirect/redirect-referrer-override.any.js (91), fetch/data-urls/processing.any.js (68), fetch/api/headers/header-values-normalize.any.js (57), fetch/api/cors/cors-keepalive.any.js (51), fetch/api/cors/cors-preflight-star.any.js (34), fetch/api/redirect/redirect-origin.any.js (30), fetch/api/cors/cors-preflight-status.any.js (27), and 110 more.

Was this page helpful?