gossamer 🕸️

Cross-runtime JavaScript API bindings for Gleam.

Package Version Hex Docs

gossamer covers Web Platform APIs (WinterTC) and ECMAScript built-ins that have no direct equivalent in Gleam’s standard library. All APIs work across Deno, Node.js, Bun, and browsers.

APIs mirror their JavaScript counterparts in structure and naming, adapted to Gleam conventions — snake_case naming, pipeable signatures, Result for throwing/nullable APIs, and Promise(Result(a, e)) for rejectable promises.

For higher-level Gleam-idiomatic abstractions, see gleam_javascript, gleam_fetch, and gleam_json.

See COVERAGE.md for the full list of implemented and planned APIs.

Installation

gleam add gossamer

Usage

import gossamer
import gossamer/promise
import gossamer/response
import gossamer/url

pub fn main() {
  let assert Ok(parsed) = url.new("https://example.com/path?q=gleam")
  let hostname = url.hostname(parsed)  // "example.com"

  use result <- promise.then(gossamer.fetch("https://example.com"))
  let assert Ok(resp) = result
  use result <- promise.then(response.text(resp))
  let assert Ok(body) = result
  promise.resolve(body)
}

Further documentation can be found at https://hexdocs.pm/gossamer.

Contributing

Prerequisites

Tip: These can also be installed via mise or asdf, which read from .tool-versions.

Initial Setup

just

Development

just watch build test
Search Document