API reference
petty.network
permission: networkpetty.network.fetch
fetch(url: string, callback: (result: FetchResult | null) => void): voidGET shorthand.
fetch(
url: string,
options: FetchOptions,
callback: (result: FetchResult | null) => void
): voidFull request with method, headers, body, and response type control.
Types referenced
FetchResult
interface FetchResult {
status: number;
/** UTF-8 decoded response body. Garbage for binary responses — use
* `bytes` instead in that case. */
body: string;
json: unknown | null;
/** Base64-encoded response bytes. Populated only when
* `options.responseType === "binary"`. */
bytes?: string;
}FetchOptions
interface FetchOptions {
/** Defaults to "GET". */
method?: HttpMethod;
/** Request headers. Values must be strings. */
headers?: Record<string, string>;
/** UTF-8 request body. Pair with a Content-Type header if needed. */
body?: string;
/** "text" (default) decodes the response as UTF-8. "binary" additionally
* returns the raw bytes as base64 in `result.bytes` — use this for audio,
* images, or any non-text response. */
responseType?: "text" | "binary";
}HttpMethod
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";