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
// 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());
elide run fetch.mjs prints:
POST multipart/form-data
201 7 {"ok":true}
3 bc
Differences from browsers
fetchacceptshttp:andhttps:URLs;data:andblob:URLs reject withunsupported URL scheme.- There is no origin:
mode,credentials,referrerandkeepaliveare accepted and ignored, and no CORS checks, preflights, cookies orRefererheaders are applied. - Requests send
User-Agent: Elide/<version>andAccept: */*unless you set those headers.ELIDE_HTTP_USER_AGENTchanges 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-Encodingheader is sent as given; range requests default toidentity. fetch(url, { decompress: false })sendsAccept-Encoding: identityand returns any encoded body unchanged.- A malformed compressed body rejects.
- There is no HTTP cache: conditional headers are sent as given, and a
304has headers and no body. Headersapplies the request, response, no-CORS and immutable guards; iteration lowercases and sorts names and keepsSet-Cookievalues 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
| Export | Kind | Status | Notes |
|---|---|---|---|
Headers | class | Full | append(), delete(), get(), getSetCookie(), has(), set(), iteration |
Request | class | Full | method, url, headers, destination, referrer, referrerPolicy, mode, credentials, cache, redirect, integrity, keepalive, signal, duplex, clone(), body, bodyUsed, arrayBuffer(), blob(), bytes(), formData(), json(), text() |
Response | class | Full | Response.error(), Response.redirect(), Response.json(), type, url, redirected, status, ok, statusText, headers, clone(), body, bodyUsed, arrayBuffer(), blob(), bytes(), formData(), json(), text() |
Blob | class | Full | size, type, slice(), text(), arrayBuffer(), bytes(), stream() |
File | class | Full | name, lastModified |
FormData | class | Full | append(), 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.