Modules

Docs / API / Modules / http

HTTP

Network

@s2script/sdk/http

async HTTP.

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
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).

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

ThrowsRejects only on a network error or timeout.

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

s2script — Source 2 plugin framework

GitHub