gossamer

Top-level cross-runtime Web Platform APIs: fetch, timers, base64, structured cloning, and more. Domain-specific APIs live in submodules (see gossamer/url, gossamer/headers, gossamer/readable_stream, etc.).

Values

pub fn atob(encoded: String) -> Result(String, js_error.JsError)

Decodes a base64-encoded string. Returns an error if the string is not valid base64.

pub fn btoa(data: String) -> Result(String, js_error.JsError)

Encodes a binary string as base64. Returns an error if data contains code points beyond 0xFF (use uint8_array.to_base64 for arbitrary bytes).

pub fn clear_interval(id: Int) -> Nil

Cancels a repeating timer previously scheduled with set_interval.

pub fn clear_timeout(id: Int) -> Nil

Cancels a one-shot timer previously scheduled with set_timeout.

pub fn fetch(
  url: String,
) -> promise.Promise(Result(response.Response, js_error.JsError))

Fetches a resource from url. Returns an error on network error, CORS failure, or if the URL is invalid.

pub fn fetch_request(
  request: request.Request,
) -> promise.Promise(Result(response.Response, js_error.JsError))

Fetches a resource using a pre-built Request. Returns an error on network error or CORS failure.

pub fn fetch_request_with(
  request: request.Request,
  with init: List(request.RequestInit),
) -> promise.Promise(Result(response.Response, js_error.JsError))

Fetches a resource using a pre-built Request, with init options that override fields on request. Returns an error on network error, CORS failure, or if init is invalid.

pub fn fetch_url(
  url: url.URL,
) -> promise.Promise(Result(response.Response, js_error.JsError))

Fetches a resource from url. Returns an error on network error or CORS failure.

pub fn fetch_url_with(
  url: url.URL,
  with init: List(request.RequestInit),
) -> promise.Promise(Result(response.Response, js_error.JsError))

Fetches a resource from url with the given request init options. Returns an error on network error, CORS failure, or if init is invalid.

pub fn fetch_with(
  url: String,
  with init: List(request.RequestInit),
) -> promise.Promise(Result(response.Response, js_error.JsError))

Fetches a resource from url with the given request init options. Returns an error on network error, CORS failure, or if the URL or init is invalid.

pub fn queue_microtask(run func: fn() -> a) -> Nil

A microtask is a short function which is executed after the function or module which created it exits and only if the JavaScript execution stack is empty, but before returning control to the event loop.

pub fn set_interval(
  every delay: Int,
  run callback: fn() -> a,
) -> Int

Schedules callback to run repeatedly every delay milliseconds. Returns an id that can be passed to clear_interval to cancel.

pub fn set_timeout(
  after delay: Int,
  run callback: fn() -> a,
) -> Int

Sets a timer which executes a function once after the delay (in milliseconds) elapses. Returns an id which may be used to cancel the timeout.

pub fn structured_clone(value: a) -> Result(a, js_error.JsError)

Creates a deep clone of value using the structured clone algorithm. Returns an error if value contains a function, symbol, or other non-cloneable value.

pub fn user_agent() -> String

Returns the runtime’s user agent string (e.g., browser identity, Deno/Node version).

Search Document