element.version === currentVersion)) { versionNodes.unshift({ version: currentVersion, url: "#" }); } document.querySelector("#project-version").innerHTML = versionNodes.reduce( (acc, element) => { const status = currentVersion === element.version ? "selected disabled" : ""; return ` ${acc} `; }, `
gossamer · v10.0.0

gossamer 🕸️

Cross-runtime JavaScript API bindings for Gleam.

Package Version Hex Docs

Node.js Deno Bun

gossamer covers Web Platform APIs (WinterTC) and ECMAScript built-ins that don’t have idiomatic Gleam wrappers yet. Bindings work across Node.js, Deno, Bun, and browsers without polyfills — the badges above show the minimum versions verified against gossamer’s test suite.

Reach for ecosystem packages first

gossamer is gap-fill. Where the Gleam ecosystem already covers a domain, use its canonical types and functions directly:

DomainUse this
HTTP requests, responses, methods, headersgleam_http
fetchgleam_fetch
URLs (RFC 3986 parsing, building)gleam/uri
Timestamps and durationsgleam_time
JSONgleam_json
Promise, Array, Symbolgleam_javascript
Iteratorsgleam_yielder
Regular expressionsgleam_regexp
Strong random bytesgleam_crypto

gossamer fills the rest: AbortSignal, Blob / File, the Streams API, SubtleCrypto, WebSocket, Worker / MessageChannel / BroadcastChannel, Intl formatters, TextDecoder / TextDecoderStream / TextEncoderStream, CompressionStream / DecompressionStream, URLPattern, BigInt, Performance / PerformanceObserver, plus per-module extras (fetch_extra, form_data_extra, time_extra, string_extra, regexp_extra, symbol_extra, int_extra, float_extra). See the coverage page for the full list.

Per-binding docs flag cross-runtime gaps where a runtime departs from spec.

Installation

gleam add gossamer gleam_fetch gleam_http gleam_javascript

gossamer’s API composes with the canonical ecosystem types, so code using it — including the example below — typically imports gleam_fetch, gleam_http, and gleam_javascript directly; add them as direct dependencies alongside gossamer.

Usage

A fetch through gossamer/fetch_extra with cache and keepalive overrides — chain setters on the FetchOptions builder, then pass it to send. The result composes with gleam/fetch’s body readers:

import gleam/fetch
import gleam/http/request
import gleam/javascript/promise
import gossamer/fetch_extra

pub fn main() {
  let assert Ok(req) = request.to("https://example.com/api")
  let opts =
    fetch_extra.options()
    |> fetch_extra.set_cache(fetch_extra.CacheNoStore)
    |> fetch_extra.set_keepalive(True)
  use resp <- promise.try_await(fetch_extra.send(req, with: opts))
  use resp <- promise.try_await(fetch.read_text_body(resp))
  promise.resolve(Ok(resp.body))
}

Further documentation lives at https://hexdocs.pm/gossamer.

Search Document