Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / http

HTTP

Network

@s2script/sdk/http

Off-thread fetch. Admission rejects with AsyncQueueFull / AsyncPayloadTooLarge; oversized responses reject with HttpResponseTooLarge.

Import

import { FetchOptions } from "@s2script/sdk/http";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

interface
FetchOptions

Options for fetch.

method?: string
— HTTP method (e.g. "GET", "POST").
headers?: Record<string, string>
— Request headers as a name→value map.
body?: string
— Request body (already-serialized string; set your own content-type).
timeoutMs?: number
— Abort the request after this many milliseconds.
interface
Response

The response from a fetch call — a copied snapshot (no live socket).

readonly status: number
— HTTP status code (e.g. 200, 404).
readonly ok: boolean
— True iff Response.status is in the 2xx range.
readonly statusText: string
— HTTP status reason phrase (e.g. "Not Found").
readonly headers: Record<string, string>
— Response headers as a lower-cased name→value map.
text(): string
— The response body decoded as text.
json<T = unknown>(): T
— Parse the response body as JSON into T (throws on invalid JSON).
fn
fetch(url: string, options?: FetchOptions): Promise<Response>

Perform an HTTP request off the game thread.

url
Absolute http(s):// URL.
options
Method, headers, body, and timeout (see FetchOptions).

Returns — Resolves for ANY HTTP response — a 4xx/5xx resolves with ok=false, it does not reject.

Throws — Rejects on a network error or timeout, or with AsyncQueueFull / AsyncPayloadTooLarge before acceptance. HttpResponseTooLarge when the retained UTF-8 body plus headers exceed the configured limit.

import { fetch } from "@s2script/sdk/http";
const r = await fetch("https://httpbin.org/get", { timeoutMs: 15000 });
if (r.ok) console.log(r.json<{ url: string }>().url);
Back to modules All packages