Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.
fetch is global. It reads method / headers / body / signal from the init object and returns a Promise<Response>. Everything else in init (timeout, redirect) is ignored. Method names are exact-case standard tokens — lowercase "post" is sent as GET (see Troubleshooting).
Permissions
Outbound requests are deny-by-default. Every fetch needs --allow-net for
the destination:
ff client.js --allow-net=api.example.com:443
The URL’s literal host is matched, lowercased. There is no DNS lookup
and no IP matching: localhost ≠ 127.0.0.1, and granting
api.example.com does not cover 93.184.216.34.
Ports matter. https://api.example.com/ checks api.example.com:443;
http://api.example.com/ checks api.example.com:80. Omit the port in the
flag to allow every port on that host.
*.example.com matches subdomains but not the apex example.com.
* (or bare --allow-net) grants every host and port.
Every redirect hop is checked again against the new URL.
TLS trust (--ca, FF_CA_FILE) is separate and does not grant network
access. Proxy variables are read by the runtime without --allow-env, and
the check applies to the destination, not the proxy host — see
fetch Proxies.
An initial URL outside the scope throws synchronously:
A redirect hop outside the scope rejects with a string instead:
"PermissionDenied: fetch requires --allow-net". Catch both shapes. Full
model: Permissions.
Quick look
// client.js(async () => { const res = await fetch("https://example.com/"); console.log(res.status); // 200 console.log(await res.text()); // body text})();
ff client.js --allow-net=example.com:443
Modules vs scripts
ff forces ES module evaluation when a file ends in .mjs. For .js files,
ff tries classic-script compilation first and automatically falls back to ES
module evaluation when the file contains import, export, or top-level
await anywhere in the source. The runnable examples on this page wrap async
code in (async () => { ... })() so they also work when pasted into classic-script
contexts.
Check res.ok — HTTP error statuses resolve, they don’t throw:
const res = await fetch("https://api.example.com/missing");if (!res.ok) { console.log("failed:", res.status); // e.g. 404}
HTTP statuses like 404 or 500 resolve normally. Network
failures (DNS, refused connection, too many redirects) reject with strings,
and an initial permission denial throws a PermissionDenied error. Always
check res.ok or res.status after a response; always handle the
permission case separately.
string bodies — and URLSearchParams, which coerces to its query string — reach the wire intact. Everything else is coerced with JS String() semantics: a FormData or Blob arrives as "[object Object]", an ArrayBuffer as "[object ArrayBuffer]", a Uint8Array([104, 105]) as "104,105".
Known issue:fetch does not multipart-encode FormData or send binary bodies as bytes. Build the payload yourself:
const params = new URLSearchParams({ name: "ada" });await fetch("https://api.example.com/submit", { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: params, // "name=ada" — URLSearchParams stringifies to its query});
Reading the response
Every reader works on Response (and Request). Bodies can be re-read freely (and bodyUsed stays false):
Reader
Returns
await res.text()
string
await res.json()
parsed JSON
await res.arrayBuffer()
ArrayBuffer
await res.bytes()
ArrayBuffer
await res.blob()
Blob
await res.formData()
FormData
const res = await fetch("https://example.com/");console.log(res.url); // final URL after redirectsconsole.log(res.redirected); // true when redirectedconsole.log(res.headers.get("content-type"));console.log((await res.bytes()).byteLength);
Redirects
Redirects are followed automatically, up to 5 hops. After that fetch throws Too many redirects:
const res = await fetch("https://example.com/old-path");console.log(res.redirected); // trueconsole.log(res.url); // where it landed
Every hop is re-checked against --allow-net. A redirect that crosses hosts
needs both scopes:
A hop outside the scope rejects with the string
"PermissionDenied: fetch requires --allow-net".There is no redirect: "manual" mode — the init key is ignored.
HTTPS trust
Public CAs work out of the box. For private/self-signed CAs:
Setup
How
One-off script
ff client.js --ca ./ca.pem (--ca works with ff <file> and ff -e only)
Any run, incl. ff start
FF_CA_FILE=./ca.pem ff start
Dev TLS pairing
Starting TLS with --cert/FF_CERT also trusts that cert for fetch
--ca is not accepted by ff start. Use FF_CA_FILE (or FF_CERT) there.
Trust and permission are independent: neither --ca nor FF_CA_FILE grants
network access, and --allow-net does not make an untrusted certificate
valid. FF_CA_FILE is runtime configuration, so it needs no --allow-env.
Practical example: synced mirror
Fetch a list, then POST each item onward, checking every status:
Both hosts need their own scope; *.example.com would cover neither of these
two apex domains.
Reference: limits
Area
Limit
When hit
Concurrent fetches
16
The 17th waits for a free slot
Body stage per slot
64KB
Larger bodies spill to chunks/heap
Response body cap
16 MB hard cap (Content-Length and decompression)
Responses beyond 16 MB reject
I/O timeout
30s
Slow servers fail
Redirects
5 hops max, each re-checked
Throws Too many redirects or rejects with a permission string
Cross-origin credentials
Stripped on cross-origin redirect
authorization, cookie, x-api-key dropped when changing origin
Header validation
RFC 7230 character validation
CRLF or invalid header characters reject before sending
Abort
AbortController / AbortSignal (signal init key)
Rejects with signal.reason and closes the socket
Protocol
HTTP/1.1
No HTTP/2 client
Troubleshooting
fetch throws PermissionDenied — the initial URL’s host and port are
outside every --allow-net scope. Add the exact target:
--allow-net=api.example.com:443. Remember localhost and 127.0.0.1 are
different scopes, and HTTPS defaults to port 443.A redirect fails with PermissionDenied: fetch requires --allow-net — a
later hop crossed into a host or port you did not grant. Grant every host in
the chain, or make the redirect target stay within one host.404 resolves instead of throwing — by design. Check res.ok / res.status after every call.Lowercase method: "post" arrives as GET — method tokens match exactly; anything unrecognized goes out as GET (the body is still attached). Use "POST".FormData / Blob / Uint8Array body arrives mangled — bodies are string-coerced, not serialized ("[object Object]", "104,105"). Send string, URLSearchParams, or a hand-built multipart string instead.Caught fetch error has no .message — most failures reject with plain strings ("Network error", "Invalid URL", "Too many redirects", and the redirect-hop permission string). Log String(e). The initial permission denial is the exception: it is an Error with .message.Too many redirects — the chain exceeded 5 hops. Inspect res.url on the last good hop or fix the redirect loop server-side.TLS verify fails on a private CA — pass --ca (scripts) or FF_CA_FILE (ff start). Confirm the PEM path is readable. Trust does not replace --allow-net.Hanging with 17+ parallel fetches — the 16-slot pool is full. Await in batches or raise concurrency by sequencing.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"fairyfly","description":"Documentation for Fairyfly, a serverless-first backend JavaScript runtime built with Zig and powered by QuickJS.","colors":{"primary":"#5f7542","light":"#a9be86","dark":"#4c5f34"},"logo":{"light":"https://mintcdn.com/fairyfly/lKP-5nOUrOLv7Po8/logo-light.svg?fit=max\u0026auto=format\u0026n=lKP-5nOUrOLv7Po8\u0026q=85\u0026s=862d0e6beb30c77db1ef81b7396f53be","dark":"https://mintcdn.com/fairyfly/lKP-5nOUrOLv7Po8/logo-dark.svg?fit=max\u0026auto=format\u0026n=lKP-5nOUrOLv7Po8\u0026q=85\u0026s=cc08030fc46bf43fb3f82a8cf19ee10a"},"favicon":"https://mintcdn.com/fairyfly/lKP-5nOUrOLv7Po8/favicon.png?fit=max\u0026auto=format\u0026n=lKP-5nOUrOLv7Po8\u0026q=85\u0026s=5c81997e3c6e9255439b8e528b5c745b","navbar":{"links":[{"icon":"star","href":"https://github.com/AbdElMajidOuhamane/ff","label":"Star on GitHub"}],"primary":{"type":"github","href":"https://github.com/AbdElMajidOuhamane/ff"}},"footer":{"socials":{"github":"https://github.com/AbdElMajidOuhamane/ff"},"links":[{"header":"Documentation","items":[{"label":"Introduction","href":"/getting-started/introduction"},{"label":"Quickstart","href":"/getting-started/quickstart"},{"label":"Permissions","href":"/concepts/permissions"},{"label":"HTTP server","href":"/guides/http-server"},{"label":"API overview","href":"/api/overview"},{"label":"CLI reference","href":"/reference/cli"},{"label":"Serverless","href":"/guides/deploy"},{"label":"Blog","href":"/blog"}]},{"header":"Guides","items":[{"label":"Fetch client","href":"/guides/fetch-client"},{"label":"WebSocket","href":"/guides/websocket"},{"label":"Workers","href":"/guides/workers"},{"label":"Packages","href":"/guides/packages"},{"label":"Deploy","href":"/guides/deploy"}]},{"header":"Reference","items":[{"label":"Limitations","href":"/reference/limitations"},{"label":"Compatibility","href":"/reference/compatibility"},{"label":"Examples","href":"/reference/examples"},{"label":"Benchmarks","href":"/blog/microvm-benchmark"}]},{"header":"Project","items":[{"label":"GitHub","href":"https://github.com/AbdElMajidOuhamane/ff"},{"label":"Releases","href":"https://github.com/AbdElMajidOuhamane/ff/releases"},{"label":"Contributing","href":"https://github.com/AbdElMajidOuhamane/ff/blob/main/CONTRIBUTING.md"},{"label":"Security","href":"https://github.com/AbdElMajidOuhamane/ff/blob/main/SECURITY.md"},{"label":"License","href":"https://github.com/AbdElMajidOuhamane/ff/blob/main/LICENSE"},{"label":"Sponsor","href":"https://github.com/sponsors/AbdElMajidOuhamane"}]}]},"seo":{"metatags":{"theme-color":"#5f7542"}},"banner":{"content":"**Serverless-first.** Built for cold starts, tight memory, and one binary. [Deploy guide →](/guides/deploy)"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"fairyfly","hasAudioNarration":false,"actualSubdomain":"fairyfly","customDomains":["fairyfly.dev","www.fairyfly.dev"],"gitSource":{"type":"github","owner":"abdelmajidouhamane","repo":"fairyfly-documentation","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":"","_id":"6af8decd9c97d4cbd7d52ffb"},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6b01804c0027a93533652fb9","clientVersion":"0.0.4271","searchFilterCounts":[{"language":"default","tag":"Guides","count":30},{"language":"default","tag":"Guide","count":23},{"language":"default","tag":"API","count":19},{"language":"default","tag":"API reference","count":19},{"language":"default","tag":"Concepts","count":10},{"language":"default","tag":"Blog","count":8},{"language":"default","tag":"Reference","count":8},{"language":"default","tag":"Getting started","count":6}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":":root{--ff-navy: #12233f;--ff-olive: #5f7542;--ff-olive-dark: #4c5f34;--ff-text-main: #12233f;--ff-text-muted: #5b6472;--ff-border: rgba(18, 35, 63, 0.12);--ff-surface-soft: rgba(95, 117, 66, 0.06)}html.dark{--ff-text-main: #f4f0e4;--ff-text-muted: #b8c0b0;--ff-olive: #a9be86;--ff-olive-dark: #8aa266;--ff-border: rgba(238, 227, 197, 0.14);--ff-surface-soft: rgba(169, 190, 134, 0.08)}img.nav-logo{height:30px!important;width:auto!important;max-width:none!important}#navbar a[href*=\"github.com\"] svg+span,#navbar a[href*=\"github.com\"]>div>div+div{display:none!important}#navbar a[href*=\"github.com\"] svg{width:1.25rem!important;height:1.25rem!important}#navbar a[href*=\"github.com\"]{padding:0.4rem!important;border-radius:0.5rem!important;transition:opacity 0.18s ease, transform 0.18s ease}#navbar a[href*=\"github.com\"]:hover{opacity:0.8;transform:translateY(-1px)}#content-area:has(.ff-hero)>header,main:has(.ff-hero) header#header,div:has(>.mdx-content .ff-hero)>header{display:none!important}@keyframes ff-fade-up{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}@keyframes ff-float{0%,100%{transform:translateY(0)}50%{transform:translateY(-7px)}}.ff-hero{padding:1.5rem 0 2.5rem;margin-bottom:1.5rem;border-bottom:1px solid var(--ff-border)}.ff-hero__grid{display:grid;grid-template-columns:minmax(0, 1.45fr) minmax(220px, 0.55fr);gap:2.5rem;align-items:center;margin-bottom:1.75rem}@media (max-width: 820px){.ff-hero__grid{grid-template-columns:1fr;gap:1.5rem;text-align:center}.ff-hero__actions{justify-content:center}}.ff-hero__copy{animation:ff-fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) both}.ff-hero__heading{margin:0 0 1rem;color:var(--ff-text-main);font-size:clamp(2rem, 3.4vw, 2.75rem);font-weight:750;line-height:1.2;letter-spacing:-0.025em}.ff-hero__brand{display:block;width:fit-content;font-size:1.35em;font-weight:850;letter-spacing:-0.04em;margin-bottom:0.25rem;background:linear-gradient(100deg, #4c5f34 0%, #8aa266 35%, #5f7542 60%, #12233f 100%);background-size:200% auto;-webkit-background-clip:text;background-clip:text;color:transparent;animation:ff-shine 6s ease-in-out infinite alternate}html.dark .ff-hero__brand{background-image:linear-gradient(100deg, #a9be86 0%, #e3edc9 35%, #8aa266 60%, #f4f0e4 100%)}@keyframes ff-shine{from{background-position:0% center}to{background-position:100% center}}@media (max-width: 820px){.ff-hero__brand{margin-inline:auto}}.ff-hero__subtitle{display:block;color:var(--ff-text-main);font-weight:650;opacity:0.88}.ff-hero__tagline{margin:0 0 1.6rem;color:var(--ff-text-muted);font-size:1.08rem;line-height:1.65;max-width:64ch}@media (max-width: 820px){.ff-hero__tagline{margin-inline:auto}}.ff-hero__actions{display:flex;flex-wrap:wrap;align-items:center;gap:0.75rem}.ff-btn{display:inline-flex;align-items:center;justify-content:center;padding:0.65rem 1.35rem;border-radius:999px;font-size:0.94rem;font-weight:600;line-height:1.2;text-decoration:none!important;border:1px solid transparent!important;transition:transform 0.18s ease, background-color 0.18s ease, border-color 0.18s ease}.ff-btn--primary{background:#5f7542!important;color:#ffffff!important}.ff-btn--primary:hover{background:#4c5f34!important;transform:translateY(-1.5px)}.ff-btn--secondary{background:var(--ff-surface-soft)!important;color:var(--ff-text-main)!important;border-color:var(--ff-border)!important}.ff-btn--secondary:hover{border-color:var(--ff-olive)!important;transform:translateY(-1.5px)}.ff-hero__visual{display:flex;justify-content:center;align-items:center;animation:ff-fade-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.08s both}.ff-hero__img{width:100%;max-width:280px;height:auto;aspect-ratio:1 / 1;object-fit:contain;margin:0!important;animation:ff-float 6s ease-in-out infinite}.ff-hero__stats{display:grid;grid-template-columns:repeat(4, minmax(0, 1fr));gap:0.75rem;margin-top:1rem;padding-top:1rem;animation:ff-fade-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.14s both}@media (max-width: 640px){.ff-hero__stats{grid-template-columns:repeat(2, minmax(0, 1fr))}}.ff-stat{display:flex;align-items:baseline;gap:0.45rem;padding:0.55rem 0.85rem;border-radius:0.65rem;background:var(--ff-surface-soft);border:1px solid var(--ff-border)}.ff-stat__value{color:var(--ff-text-main);font-size:1.15rem;font-weight:750;letter-spacing:-0.02em}.ff-stat__label{color:var(--ff-text-muted);font-size:0.84rem}.ff-landing{margin:0 auto}@media (prefers-reduced-motion: reduce){.ff-hero__copy,.ff-hero__visual,.ff-hero__stats,.ff-hero__img{animation:none!important}}"}]}
{"page":{"pagePath":"guides/fetch-client","slug":"/guides/fetch-client","pageMetadata":{"title":"Fetch Client","description":"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.","href":"/guides/fetch-client"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[_jsx(_components.code,{children:`fetch`}),` is global. It reads `,_jsx(_components.code,{children:`method`}),` / `,_jsx(_components.code,{children:`headers`}),` / `,_jsx(_components.code,{children:`body`}),` / `,_jsx(_components.code,{children:`signal`}),` from the init object and returns a `,_jsx(_components.code,{children:`Promise\u003cResponse>`}),`. Everything else in init (`,_jsx(_components.code,{children:`timeout`}),`, `,_jsx(_components.code,{children:`redirect`}),`) is ignored. Method names are exact-case standard tokens — lowercase `,_jsx(_components.code,{children:`\"post\"`}),` is sent as `,_jsx(_components.code,{children:`GET`}),` (see Troubleshooting).`]}),`\n`,_jsx(Heading,{level:`2`,id:`permissions`,children:`Permissions`}),`\n`,_jsxs(_components.p,{children:[`Outbound requests are deny-by-default. Every `,_jsx(_components.code,{children:`fetch`}),` needs `,_jsx(_components.code,{children:`--allow-net`}),` for\nthe destination:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` client.js`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=api.example.com:443`})]}),`\n`]})})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`The URL’s `,_jsx(_components.strong,{children:`literal host`}),` is matched, lowercased. There is no DNS lookup\nand no IP matching: `,_jsx(_components.code,{children:`localhost`}),` ≠ `,_jsx(_components.code,{children:`127.0.0.1`}),`, and granting\n`,_jsx(_components.code,{children:`api.example.com`}),` does not cover `,_jsx(_components.code,{children:`93.184.216.34`}),`.`]}),`\n`,_jsxs(_components.li,{children:[`Ports matter. `,_jsx(_components.code,{children:`https://api.example.com/`}),` checks `,_jsx(_components.code,{children:`api.example.com:443`}),`;\n`,_jsx(_components.code,{children:`http://api.example.com/`}),` checks `,_jsx(_components.code,{children:`api.example.com:80`}),`. Omit the port in the\nflag to allow every port on that host.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`*.example.com`}),` matches subdomains but `,_jsx(_components.strong,{children:`not`}),` the apex `,_jsx(_components.code,{children:`example.com`}),`.\n`,_jsx(_components.code,{children:`*`}),` (or bare `,_jsx(_components.code,{children:`--allow-net`}),`) grants every host and port.`]}),`\n`,_jsx(_components.li,{children:`Every redirect hop is checked again against the new URL.`}),`\n`,_jsxs(_components.li,{children:[`TLS trust (`,_jsx(_components.code,{children:`--ca`}),`, `,_jsx(_components.code,{children:`FF_CA_FILE`}),`) is separate and does not grant network\naccess. Proxy variables are read by the runtime without `,_jsx(_components.code,{children:`--allow-env`}),`, and\nthe check applies to the destination, not the proxy host — see\n`,_jsx(_components.a,{href:`/api/fetch#proxies`,children:`fetch Proxies`}),`.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`An initial URL outside the scope `,_jsx(_components.strong,{children:`throws synchronously`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.example.com/items\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`code`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// PermissionDenied PERMISSION_DENIED`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`e`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// fetch requires --allow-net for 'api.example.com:443'`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`A redirect hop outside the scope `,_jsx(_components.strong,{children:`rejects with a string`}),` instead:\n`,_jsx(_components.code,{children:`\"PermissionDenied: fetch requires --allow-net\"`}),`. Catch both shapes. Full\nmodel: `,_jsx(_components.a,{href:`/concepts/permissions`,children:`Permissions`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`quick-look`,children:`Quick look`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// client.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://example.com/\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`status`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// 200`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`text`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// body text`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})();`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` client.js`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=example.com:443`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`modules-vs-scripts`,children:`Modules vs scripts`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`ff`}),` forces ES module evaluation when a file ends in `,_jsx(_components.code,{children:`.mjs`}),`. For `,_jsx(_components.code,{children:`.js`}),` files,\n`,_jsx(_components.code,{children:`ff`}),` tries classic-script compilation first and automatically falls back to ES\nmodule evaluation when the file contains `,_jsx(_components.code,{children:`import`}),`, `,_jsx(_components.code,{children:`export`}),`, or top-level\n`,_jsx(_components.code,{children:`await`}),` anywhere in the source. The runnable examples on this page wrap async\ncode in `,_jsx(_components.code,{children:`(async () => { ... })()`}),` so they also work when pasted into classic-script\ncontexts.`]}),`\n`,_jsx(Heading,{level:`2`,id:`get-with-headers`,children:`GET with headers`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// client.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.example.com/users/42\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`authorization:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Bearer TOKEN\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`status`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// 200`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// true when 200–299`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})();`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` client.js`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=api.example.com:443`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Check `,_jsx(_components.code,{children:`res.ok`}),` — HTTP error statuses `,_jsx(_components.strong,{children:`resolve`}),`, they don’t throw:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.example.com/missing\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"failed:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`status`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// e.g. 404`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`HTTP statuses like `,_jsx(_components.code,{children:`404`}),` or `,_jsx(_components.code,{children:`500`}),` resolve normally. Network\nfailures (DNS, refused connection, too many redirects) reject with strings,\nand an initial permission denial throws a `,_jsx(_components.code,{children:`PermissionDenied`}),` error. Always\ncheck `,_jsx(_components.code,{children:`res.ok`}),` or `,_jsx(_components.code,{children:`res.status`}),` after a response; always handle the\npermission case separately.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`post-json`,children:`POST JSON`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// client.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.example.com/notes\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"POST\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content-type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"application/json\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`text:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"buy milk\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`data`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// e.g. { id: 1, text: \"buy milk\" }`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})();`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` client.js`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=api.example.com:443`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`string`}),` bodies — and `,_jsx(_components.code,{children:`URLSearchParams`}),`, which coerces to its query string — reach the wire intact. Everything else is coerced with JS `,_jsx(_components.code,{children:`String()`}),` semantics: a `,_jsx(_components.code,{children:`FormData`}),` or `,_jsx(_components.code,{children:`Blob`}),` arrives as `,_jsx(_components.code,{children:`\"[object Object]\"`}),`, an `,_jsx(_components.code,{children:`ArrayBuffer`}),` as `,_jsx(_components.code,{children:`\"[object ArrayBuffer]\"`}),`, a `,_jsx(_components.code,{children:`Uint8Array([104, 105])`}),` as `,_jsx(_components.code,{children:`\"104,105\"`}),`.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Known issue:`}),` `,_jsx(_components.code,{children:`fetch`}),` does not multipart-encode `,_jsx(_components.code,{children:`FormData`}),` or send binary bodies as bytes. Build the payload yourself:`]})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` params`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` URLSearchParams`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"ada\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.example.com/submit\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"POST\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content-type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"application/x-www-form-urlencoded\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` body:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` params`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// \"name=ada\" — URLSearchParams stringifies to its query`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`reading-the-response`,children:`Reading the response`}),`\n`,_jsxs(_components.p,{children:[`Every reader works on `,_jsx(_components.code,{children:`Response`}),` (and `,_jsx(_components.code,{children:`Request`}),`). Bodies can be re-read freely (and `,_jsx(_components.code,{children:`bodyUsed`}),` stays `,_jsx(_components.code,{children:`false`}),`):`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Reader`}),_jsx(_components.th,{children:`Returns`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`await res.text()`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`string`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`await res.json()`})}),_jsx(_components.td,{children:`parsed JSON`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`await res.arrayBuffer()`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ArrayBuffer`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`await res.bytes()`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`ArrayBuffer`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`await res.blob()`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`Blob`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`await res.formData()`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`FormData`})})]})]})]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://example.com/\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`url`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// final URL after redirects`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`redirected`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// true when redirected`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`headers`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`get`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content-type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`));`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`((`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`bytes`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()).`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`byteLength`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`redirects`,children:`Redirects`}),`\n`,_jsxs(_components.p,{children:[`Redirects are followed automatically, up to `,_jsx(_components.strong,{children:`5 hops`}),`. After that `,_jsx(_components.code,{children:`fetch`}),` throws `,_jsx(_components.code,{children:`Too many redirects`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` res`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://example.com/old-path\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`redirected`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// true`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`res`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`url`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// where it landed`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Every hop is re-checked against `,_jsx(_components.code,{children:`--allow-net`}),`. A redirect that crosses hosts\nneeds both scopes:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` client.js`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=example.com,cdn.example.com`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`A hop outside the scope rejects with the string\n`,_jsx(_components.code,{children:`\"PermissionDenied: fetch requires --allow-net\"`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`There is no `,_jsx(_components.code,{children:`redirect: \"manual\"`}),` mode — the init key is ignored.`]}),`\n`,_jsx(Heading,{level:`2`,id:`https-trust`,children:`HTTPS trust`}),`\n`,_jsx(_components.p,{children:`Public CAs work out of the box. For private/self-signed CAs:`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Setup`}),_jsx(_components.th,{children:`How`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`One-off script`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`ff client.js --ca ./ca.pem`}),` (`,_jsx(_components.code,{children:`--ca`}),` works with `,_jsx(_components.code,{children:`ff \u003cfile>`}),` and `,_jsx(_components.code,{children:`ff -e`}),` only)`]})]}),_jsxs(_components.tr,{children:[_jsxs(_components.td,{children:[`Any run, incl. `,_jsx(_components.code,{children:`ff start`})]}),_jsx(_components.td,{children:_jsx(_components.code,{children:`FF_CA_FILE=./ca.pem ff start`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Dev TLS pairing`}),_jsxs(_components.td,{children:[`Starting TLS with `,_jsx(_components.code,{children:`--cert`}),`/`,_jsx(_components.code,{children:`FF_CERT`}),` also trusts that cert for `,_jsx(_components.code,{children:`fetch`})]})]})]})]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`FF_CA_FILE`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`./ca.pem`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:` ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` client.js`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=api.example.com:443`})]}),`\n`]})})}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`--ca`}),` is `,_jsx(_components.strong,{children:`not`}),` accepted by `,_jsx(_components.code,{children:`ff start`}),`. Use `,_jsx(_components.code,{children:`FF_CA_FILE`}),` (or `,_jsx(_components.code,{children:`FF_CERT`}),`) there.`]})}),`\n`,_jsxs(_components.p,{children:[`Trust and permission are independent: neither `,_jsx(_components.code,{children:`--ca`}),` nor `,_jsx(_components.code,{children:`FF_CA_FILE`}),` grants\nnetwork access, and `,_jsx(_components.code,{children:`--allow-net`}),` does not make an untrusted certificate\nvalid. `,_jsx(_components.code,{children:`FF_CA_FILE`}),` is runtime configuration, so it needs no `,_jsx(_components.code,{children:`--allow-env`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`practical-example-synced-mirror`,children:`Practical example: synced mirror`}),`\n`,_jsx(_components.p,{children:`Fetch a list, then POST each item onward, checking every status:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`14`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`14`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// mirror.js`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` src`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.example.com/items\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`src`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ok`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`throw`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`source: \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`src`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`status`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` item`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` src`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` dst`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://backup.example.com/items\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` method:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"POST\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` headers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content-type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"application/json\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` body:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` JSON`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stringify`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`item`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`item`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`dst`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`status`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})();`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`ff`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` mirror.js`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --allow-net=api.example.com:443,backup.example.com:443`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Both hosts need their own scope; `,_jsx(_components.code,{children:`*.example.com`}),` would cover neither of these\ntwo apex domains.`]}),`\n`,_jsx(Heading,{level:`2`,id:`reference-limits`,children:`Reference: limits`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Area`}),_jsx(_components.th,{children:`Limit`}),_jsx(_components.th,{children:`When hit`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Concurrent fetches`}),_jsx(_components.td,{\"data-numeric\":`true`,children:`16`}),_jsx(_components.td,{children:`The 17th waits for a free slot`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Body stage per slot`}),_jsx(_components.td,{\"data-numeric\":`true`,children:`64KB`}),_jsx(_components.td,{children:`Larger bodies spill to chunks/heap`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Response body cap`}),_jsx(_components.td,{children:`16 MB hard cap (Content-Length and decompression)`}),_jsx(_components.td,{children:`Responses beyond 16 MB reject`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`I/O timeout`}),_jsx(_components.td,{\"data-numeric\":`true`,children:`30s`}),_jsx(_components.td,{children:`Slow servers fail`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Redirects`}),_jsx(_components.td,{children:`5 hops max, each re-checked`}),_jsxs(_components.td,{children:[`Throws `,_jsx(_components.code,{children:`Too many redirects`}),` or rejects with a permission string`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Cross-origin credentials`}),_jsx(_components.td,{children:`Stripped on cross-origin redirect`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`authorization`}),`, `,_jsx(_components.code,{children:`cookie`}),`, `,_jsx(_components.code,{children:`x-api-key`}),` dropped when changing origin`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Header validation`}),_jsx(_components.td,{children:`RFC 7230 character validation`}),_jsx(_components.td,{children:`CRLF or invalid header characters reject before sending`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Abort`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`AbortController`}),` / `,_jsx(_components.code,{children:`AbortSignal`}),` (`,_jsx(_components.code,{children:`signal`}),` init key)`]}),_jsxs(_components.td,{children:[`Rejects with `,_jsx(_components.code,{children:`signal.reason`}),` and closes the socket`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Protocol`}),_jsx(_components.td,{children:`HTTP/1.1`}),_jsx(_components.td,{children:`No HTTP/2 client`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`troubleshooting`,children:`Troubleshooting`}),`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[_jsx(_components.code,{children:`fetch`}),` throws `,_jsx(_components.code,{children:`PermissionDenied`})]}),` — the initial URL’s host and port are\noutside every `,_jsx(_components.code,{children:`--allow-net`}),` scope. Add the exact target:\n`,_jsx(_components.code,{children:`--allow-net=api.example.com:443`}),`. Remember `,_jsx(_components.code,{children:`localhost`}),` and `,_jsx(_components.code,{children:`127.0.0.1`}),` are\ndifferent scopes, and HTTPS defaults to port 443.`]}),`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[`A redirect fails with `,_jsx(_components.code,{children:`PermissionDenied: fetch requires --allow-net`})]}),` — a\nlater hop crossed into a host or port you did not grant. Grant every host in\nthe chain, or make the redirect target stay within one host.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`404 resolves instead of throwing`}),` — by design. Check `,_jsx(_components.code,{children:`res.ok`}),` / `,_jsx(_components.code,{children:`res.status`}),` after every call.`]}),`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[`Lowercase `,_jsx(_components.code,{children:`method: \"post\"`}),` arrives as `,_jsx(_components.code,{children:`GET`})]}),` — method tokens match exactly; anything unrecognized goes out as `,_jsx(_components.code,{children:`GET`}),` (the body is still attached). Use `,_jsx(_components.code,{children:`\"POST\"`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[_jsx(_components.code,{children:`FormData`}),` / `,_jsx(_components.code,{children:`Blob`}),` / `,_jsx(_components.code,{children:`Uint8Array`}),` body arrives mangled`]}),` — bodies are string-coerced, not serialized (`,_jsx(_components.code,{children:`\"[object Object]\"`}),`, `,_jsx(_components.code,{children:`\"104,105\"`}),`). Send `,_jsx(_components.code,{children:`string`}),`, `,_jsx(_components.code,{children:`URLSearchParams`}),`, or a hand-built multipart string instead.`]}),`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[`Caught fetch error has no `,_jsx(_components.code,{children:`.message`})]}),` — most failures reject with plain strings (`,_jsx(_components.code,{children:`\"Network error\"`}),`, `,_jsx(_components.code,{children:`\"Invalid URL\"`}),`, `,_jsx(_components.code,{children:`\"Too many redirects\"`}),`, and the redirect-hop permission string). Log `,_jsx(_components.code,{children:`String(e)`}),`. The initial permission denial is the exception: it is an `,_jsx(_components.code,{children:`Error`}),` with `,_jsx(_components.code,{children:`.message`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`Too many redirects`})}),` — the chain exceeded 5 hops. Inspect `,_jsx(_components.code,{children:`res.url`}),` on the last good hop or fix the redirect loop server-side.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`TLS verify fails on a private CA`}),` — pass `,_jsx(_components.code,{children:`--ca`}),` (scripts) or `,_jsx(_components.code,{children:`FF_CA_FILE`}),` (`,_jsx(_components.code,{children:`ff start`}),`). Confirm the PEM path is readable. Trust does not replace `,_jsx(_components.code,{children:`--allow-net`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Hanging with 17+ parallel fetches`}),` — the 16-slot pool is full. Await in batches or raise concurrency by sequencing.`]}),`\n`,_jsx(Heading,{level:`2`,id:`see-also`,children:`See also`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/concepts/permissions`,children:`Permissions`}),` — flags, scopes, denial contract`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/api/fetch`,children:`fetch API`}),` — full reference, proxies, gotchas`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/guides/http-server`,children:`HTTP Server guide`}),` — serving instead of calling`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/reference/limitations`,children:`Limitations`}),` — every hard cap`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Fetch Client","description":"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.","href":"/guides/fetch-client"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Permissions","slug":"permissions","depth":2,"children":[]},{"title":"Quick look","slug":"quick-look","depth":2,"children":[]},{"title":"Modules vs scripts","slug":"modules-vs-scripts","depth":2,"children":[]},{"title":"GET with headers","slug":"get-with-headers","depth":2,"children":[]},{"title":"POST JSON","slug":"post-json","depth":2,"children":[]},{"title":"Reading the response","slug":"reading-the-response","depth":2,"children":[]},{"title":"Redirects","slug":"redirects","depth":2,"children":[]},{"title":"HTTPS trust","slug":"https-trust","depth":2,"children":[]},{"title":"Practical example: synced mirror","slug":"practical-example-synced-mirror","depth":2,"children":[]},{"title":"Reference: limits","slug":"reference-limits","depth":2,"children":[]},{"title":"Troubleshooting","slug":"troubleshooting","depth":2,"children":[]},{"title":"See also","slug":"see-also","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"fairyfly","siteName":"fairyfly","title":"Fetch Client - fairyfly","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-15T11:25:31.661Z","originalFileLocation":"guides/fetch-client.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.\">\u003cmeta data-mint-head name=\"application-name\" content=\"fairyfly\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Fetch Client - fairyfly\">\u003cmeta data-mint-head property=\"og:description\" content=\"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"fairyfly\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://fairyfly.dev/guides/fetch-client\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://fairyfly.mintlify.site/_mintlify/api/og/v2?division=Guides\u0026amp;title=Fetch+Client\u0026amp;description=Call+other+APIs+with+fetch+%E2%80%94+GET%2C+POST%2C+JSON%2C+errors%2C+redirects%2C+and+HTTPS+trust.\u0026amp;theme=41d35be07febaba2b71bca05\u0026amp;signature=437baa5e54ac730ae9309942cd3de10c7f211f2055e703f3a0a50b8f0da50ca7\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Fetch Client - fairyfly\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://fairyfly.mintlify.site/_mintlify/api/og/v2?division=Guides\u0026amp;title=Fetch+Client\u0026amp;description=Call+other+APIs+with+fetch+%E2%80%94+GET%2C+POST%2C+JSON%2C+errors%2C+redirects%2C+and+HTTPS+trust.\u0026amp;theme=41d35be07febaba2b71bca05\u0026amp;signature=437baa5e54ac730ae9309942cd3de10c7f211f2055e703f3a0a50b8f0da50ca7\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/fairyfly/Q7TYtoBa5NDzy9WU/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"fairyfly\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#5f7542\">\u003cmeta data-mint-head name=\"theme-color\" content=\"#5f7542\">\u003clink data-mint-head rel=\"canonical\" href=\"https://fairyfly.dev/guides/fetch-client\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/guides/fetch-client.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://fairyfly.dev/#organization\",\"name\":\"fairyfly\",\"url\":\"https://fairyfly.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/fairyfly/lKP-5nOUrOLv7Po8/logo-light.svg?fit=max\u0026auto=format\u0026n=lKP-5nOUrOLv7Po8\u0026q=85\u0026s=862d0e6beb30c77db1ef81b7396f53be\"}},{\"@type\":\"WebSite\",\"@id\":\"https://fairyfly.dev#website\",\"name\":\"fairyfly\",\"url\":\"https://fairyfly.dev\",\"publisher\":{\"@id\":\"https://fairyfly.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://fairyfly.dev/guides/fetch-client#webpage\",\"url\":\"https://fairyfly.dev/guides/fetch-client\",\"name\":\"Fetch Client\",\"description\":\"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.\",\"dateModified\":\"2026-11-15T11:25:31.661Z\",\"isPartOf\":{\"@id\":\"https://fairyfly.dev#website\"},\"breadcrumb\":{\"@id\":\"https://fairyfly.dev/guides/fetch-client#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://fairyfly.dev/guides/fetch-client#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Guides\",\"item\":\"https://fairyfly.dev/guides/http-server\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fetch Client\",\"item\":\"https://fairyfly.dev/guides/fetch-client\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://fairyfly.dev/guides/fetch-client#article\",\"headline\":\"Fetch Client\",\"name\":\"Fetch Client\",\"description\":\"Call other APIs with fetch — GET, POST, JSON, errors, redirects, and HTTPS trust.\",\"url\":\"https://fairyfly.dev/guides/fetch-client\",\"mainEntityOfPage\":{\"@id\":\"https://fairyfly.dev/guides/fetch-client#webpage\"},\"dateModified\":\"2026-11-15T11:25:31.661Z\",\"publisher\":{\"@id\":\"https://fairyfly.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://fairyfly.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"fairyfly\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"fairyfly\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/guides/fetch-client.md","siteName":"fairyfly","nav":{"global":null,"tabs":[{"tab":"Home","hidden":true,"pages":[{"title":"Home","href":""}]},{"tab":"Guide","menu":[{"item":"Getting started","pages":[{"title":"Getting started","href":"/getting-started/introduction"}]},{"item":"Concepts","pages":[{"title":"Concepts","href":"/concepts/event-loop"}]},{"item":"Guides","groups":[{"group":"Guides","pages":[{"title":"HTTP Server","description":"Start a server with http.serve — from hello-world to a JSON REST API.","href":"/guides/http-server"},{"title":"Fetch Client","href":"/guides/fetch-client"},{"title":"WebSocket","description":"Real-time chat-style messaging — server upgrades, broadcast, and clients.","href":"/guides/websocket"},{"title":"TLS","href":"/guides/tls"},{"title":"HTTP/2","href":"/guides/http2"},{"title":"Workers","href":"/guides/workers"},{"title":"Timers","href":"/guides/timers"},{"title":"Logging","href":"/guides/logging"},{"title":"Modules","href":"/guides/modules"},{"title":"Process","href":"/guides/process"},{"title":"Environment Variables","sidebarTitle":"Environment variables","href":"/guides/env"},{"title":"Packages","href":"/guides/packages"},{"title":"Bytecode","href":"/guides/bytecode"},{"title":"Testing","href":"/guides/testing"},{"title":"Deploy","href":"/guides/deploy"}]}]},{"item":"Serverless","href":"/guides/deploy"}]},{"tab":"API","pages":[{"title":"API","href":"/api/overview"}]},{"tab":"Reference","pages":[{"title":"Reference","href":"/reference/cli"}]},{"tab":"Blog","pages":[{"title":"Blog","href":"/blog"}]}]},"basePath":"","title":"Fetch Client - fairyfly","deploymentId":"dpl_Em2U4NQQ2N2DE3HPbPUJVZLnAtvc","buildId":"dpl_Em2U4NQQ2N2DE3HPbPUJVZLnAtvc","dynamics":["10e4515597"],"chunks":["BannerMarkdown-CVKwuln2.js","dist-CXMB3QQU.js","lib-DMeTj1gb.js","lib-B8HbPgcC.js","katex-Dbtb6Wk7.js","html-void-elements-mCSPHezU.js","marked.esm-CZWythHk.js"]}